-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Another "Composite-id and a load query sql" proble
PostPosted: Thu Oct 06, 2005 11:58 am 
Newbie

Joined: Thu Oct 06, 2005 11:33 am
Posts: 3
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.


Top
 Profile  
 
 Post subject: My Hibernate version is 3.0.5
PostPosted: Thu Oct 06, 2005 12:04 pm 
Newbie

Joined: Thu Oct 06, 2005 11:33 am
Posts: 3
My Hibernate version is 3.0.5


Top
 Profile  
 
 Post subject: Solved
PostPosted: Fri Oct 07, 2005 12:03 am 
Newbie

Joined: Thu Oct 06, 2005 11:33 am
Posts: 3
Problem solved. Sorry for my fault.
I corrected the sql-query:
Code:
<sql-query name="allRoles">
   <load-collection alias="psnrole" role="campus.security.CampusUnit.allRoles"/>
   select {psnrole.*}
   from INFO_ROLE_VIEW psnrole
   where psnrole.unitid = :unitid
</sql-query>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.