| |

VerySource

 Forgot password?
 Register
Search
View: 832|Reply: 9

Hibernate uses Criteria to do sub-queries.

[Copy link]

1

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-3-18 13:00:01
| Show all posts |Read mode
My user has two set attributes inside, role and station. When I want to check the user that contains the role and station attributes, the error is as follows
Caused by: java.sql.SQLException: ORA-00918: column ambiguously defined

I read the sql statement, I know the cause of the error, but I don't know how to solve it!

The problem lies in as EmpID! (There are two as EmpID)
I use Criteria to query, there is no sql and hsql, so I don't know how to change the alias so that it does not conflict. Which expert can help! !! ? ? ?

select * from (select this_.id as id2_2_, this_.DelFlag as DelFlag2_2_, this_.EmpNm as EmpNm2_2_, this_.EmpNum as EmpNum2_2_, this_.LastUpdater as LastUpda5_2_2_, this_.LastUpdTm as LastUpdTm_2_2, Mobile. as Pswd2_2_, this_.Remark as Remark2_2_, this_.Status as Status2_2_, role4_.EmpID as EmpID1, role2_.id as RoleID, role2_.id as id8_0_, role2_.Role as Role8_0_, station6_.EmpID as EmpID, station1_.id as Sta , station1_.id as id6_1_, station1_.DelFlag as DelFlag6_1_, station1_.StaCode as StaCode6_1_, station1_.StaNm as StaNm6_1_ from tblUser this_, tblUserRole role4_, tblRole role2_, tblUserStation station6_, tblStation station_ID_le4 this place RoleID = role2_.id and this_.id = station6_.EmpID and station6_.StaID = station1_.id and station1_.id in (8, 9) and role2_.id in (1) and (1 = 1) and this_.DelFlag < > 6 and this_.id <> 2 order by this_.id asc) where rownum <= 10
Reply

Use magic Report

1

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-6-23 20:45:01
| Show all posts
Thank you, brothers and sisters, who can help! ! !
Reply

Use magic Report

0

Threads

39

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-6-30 22:00:01
| Show all posts
What is the Criteria query code?
Reply

Use magic Report

1

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-7-8 11:15:01
| Show all posts
Criteria userCriteria = session.createCriteria(User.class);
Criteria stationCriteria = userCriteria.createCriteria("station");
Criteria roleCriteria = userCriteria.createCriteria("role");
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-18 12:30:01
| Show all posts
select * from (

select
this_.id as id2_2_,
this_.DelFlag as DelFlag2_2_,
this_.EmpNm as EmpNm2_2_,
this_.EmpNum as EmpNum2_2_,
this_.LastUpdater as LastUpda5_2_2_,
this_.LastUpdTm as LastUpdTm2_2_,
this_.Mobile as Mobile2_2_,
this_.Pswd as Pswd2_2_,
this_.Remark as Remark2_2_,
this_.Status as Status2_2_,
role4_.EmpID as EmpID1, (as EmpID1)
role2_.id as RoleID,
role2_.id as id8_0_,
role2_.Role as Role8_0_,
station6_.EmpID as EmpID, (as EmpID)
station1_.id as StaID,
station1_.id as id6_1_,
station1_.DelFlag as DelFlag6_1_,
station1_.StaCode as StaCode6_1_,
station1_.StaNm as StaNm6_1_

from tblUser this_, tblUserRole role4_, tblRole role2_, tblUserStation station6_, tblStation station1_

where this_.id=role4_.EmpID and role4_.RoleID=role2_.id and this_.id=station6_.EmpID and station6_.StaID=station1_.id and station1_.id in (8, 9) and role2_.id in (1) and (1=1) and this_.DelFlag<>6 and this_.id<>2

order by this_.id asc)


where rownum <= 10

The as in sql means as an alias.
Reply

Use magic Report

1

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-7-18 15:30:01
| Show all posts
This brother didn't understand what I meant, SQL was generated by HIBERNATE himself!
Reply

Use magic Report

1

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-7-18 16:15:01
| Show all posts
as EmpID1 is modified by me to test SQL, HIBERNATE generates as EmpID (two!)
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-18 17:45:02
| Show all posts
Map out to see
Reply

Use magic Report

1

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-7-23 16:45:02
| Show all posts
<set
            name="role"
            table="tblUserRole"
            lazy="false"
            cascade="none"
            sort="unsorted"
        >

            <key
                column="EmpID"
            >
            </key>

            <many-to-many
                class="com.fedex.qilin.sps.admin.entity.Role"
                column="RoleID"
                outer-join="auto"
             />

        </set>

<set
            name="station"
            table="tblUserStation"
            lazy="false"
            cascade="none"
            sort="unsorted"
        >

            <key
                column="'EmpID'"
            >
            </key>

            <many-to-many
                class="com.fedex.qilin.sps.admin.entity.Station"
                column="StaID"
                outer-join="auto"
             />

        </set>
Reply

Use magic Report

1

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-7-25 08:15:01
| Show all posts
can somebody help me please? or how to find out this relationship using HSQL query
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list