Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.0
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Pls check this example:
Code:
<class name="campus.info.user.PsnRole" table="INFO_ROLE_VIEW">
<composite-id name="psnRoleId" class="campus.info.user.PsnRoleId">
<key-property name="userid" column="userid"/>
<key-property name="unitId" column="unitid"/>
</composite-id>
....
</class>
<class name="campus.security.CampusUnit" table="UNITS">
<id name="unitId" type="string" unsaved-value="0">
<generator class="assigned"/>
</id>
<set name="roles1" inverse="true" lazy="true" cascade="all-delete-orphan" order-by="userid">
<key column="unitid"/>
<one-to-many class="campus.info.user.PsnRole"/>
</set>
<set name="roles2" inverse="true" lazy="true" cascade="all-delete-orphan" order-by="userid">
<key column="unitid"/>
<one-to-many class="campus.info.user.PsnRole"/>
<loader query-ref="allRoles"/>
</set>
......
</class>
<sql-query name="allRoles">
<return alias="psnrole" class="campus.info.user.PsnRole"/>
select userid as {psnrole.userid}, unitid as {psnrole.unitId},
userid as {psnrole.psnRoleId.userid}, unitid as {psnrole.psnRoleId.unitId},
userid as {psnrole.userid}, unitid as {psnrole.unitId}, ........
from INFO_ROLE_VIEW where unitid = :unitid
</sql-query>
In "CampusUnit", the set "roles1" work perfectly, the sql generated by hb is
Code:
select roles0_.unitid as unitid1_, roles0_.userid as userid1_,
roles0_.userid as userid0_, roles0_.unitid as unitid0_,
roles0_.userid as userid2_0_, roles0_.unitid as unitid2_0_, .....
from INFO_ROLE_VIEW roles0_ where roles0_.unitid=? order by roles0_.userid
but the set "roles2" dosnt work, the sql generated by hb is
Code:
select userid as userid0_, unitid as unitid0_,
userid as userid2_0_, unitid as unitid2_0_, .......
from INFO_ROLE_VIEW where unitid = ?
I found that the sql in "roles2" missed "roles0_.unitid as unitid1_, roles0_.userid as userid1_, ".Should it be the problem?how to work it out??
Any help will be appreciated.