-->
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.  [ 9 posts ] 
Author Message
 Post subject: HQL: How can I reach a part of a key-many-to-one Relation?
PostPosted: Mon Aug 15, 2005 3:42 pm 
Beginner
Beginner

Joined: Wed Jul 20, 2005 2:57 pm
Posts: 28
Hi!

I want to make a Query like this in HQL:
Code:
Select * from player where LeagueID = 1;

The problem is that the primary key is a many-to-one relation to an other table. The Mapping for the player-table looks like that:

Code:
<composide-id>
<key-many-to-one
   name="fk_player"
   class ="Team">
   <column name="LeagueID"/>
   <column name="Teamname"/>
</key-many-to-one>
<key-property .../>
...


Can anybody give me a hint?

Thanks in advance,
Kurt


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 15, 2005 4:13 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 3:15 pm
Posts: 29
Give your composite-id a name="myKey" and then access it like:
Select * from player where myKey.LeagueID = 1;

Hope that helps,
B

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 3:42 am 
Beginner
Beginner

Joined: Wed Jul 20, 2005 2:57 pm
Posts: 28
When I give a name to my composite ID
I get the following Error messages:
Quote:
ERROR net.sf.hibernate.cfg.Configuration - Could not compile the mapping document

PropertyNotFoundException: field not found: myPK


I've no idea how to continue :-(

Any help is greatly appreciated.

Regards,
Kurt


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 3:56 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Post your modified hbm.xml so that people can have a look.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 4:35 am 
Beginner
Beginner

Joined: Wed Jul 20, 2005 2:57 pm
Posts: 28
That is the modified mappping (change: set composite-id name)

Code:
<class
   name="Player"
   table="player"
   >
   <composite-id name="myPK">
      <key-many-to-one
         name="fk_player"
         class="Team">
         <column name="leagueID" not-null="true"/>
         <column name="teamname" not-null="true"/>       
      </key-many-to-one>
      <key-property name="playernr" type="int" column="playernr"/>
   </composite-id>

   <property ....


With that mapping I get the Error messages I told about.

Regards, Kurt


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 4:46 am 
Beginner
Beginner

Joined: Wed Jul 20, 2005 2:57 pm
Posts: 28
...in the Team.hbm.xml the PK is a composite-id (leagueID, teamname) too.
The leageID there is a many-to-one relation to table league


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 10:10 am 
Beginner
Beginner

Joined: Tue Jun 21, 2005 3:15 pm
Posts: 29
Below is my example of a mapping that I use that has a many to one to "AuditMain" the composite key here has an Id class associated with it. The composite Key has auditId and stationNumber which are FK from AuditMain.
Below PosReport is a snippet of AuditMain that shows the relationship (Set) to PosReport. This is similar to yours. See if this makes sense.

<!-- THIS IS PosReport BLOB holder -->
<hibernate-mapping>

<class name="com.retail.rtfa.domain.PosReport" table="POS_REPORT" schema="RTFA">
<composite-id name="id" class="com.retail.rtfa.domain.PosReportId">
<key-property name="registerId" type="string">
<column name="REGISTER_ID" length="16" />
</key-property>
<key-property name="importDate" type="java.sql.Timestamp">
<column name="IMPORT_DATE" length="7" />
</key-property>
<key-property name="auditId" type="long">
<column name="AUDIT_ID" precision="10" scale="0" />
</key-property>
<key-property name="stationNumber" type="string">
<column name="STATION_NUMBER" length="5" />
</key-property>
</composite-id>
<many-to-one name="auditMain" class="com.retail.rtfa.domain.AuditMain" update="false" insert="false">
<column name="AUDIT_ID" precision="10" scale="0" not-null="true" />
<column name="STATION_NUMBER" length="5" not-null="true" />
</many-to-one>
<property name="report" type="blob">
<column name="REPORT" />
</property>
</class>
</hibernate-mapping>
<!-- THIS IS THE END OF PosReport BLOB holder -->
<!-- THIS IS THE RELATIONSHIP IN AUDITMAIN -->



<set name="posReports" inverse="true">
<key>
<column name="AUDIT_ID" precision="10"
scale="0" not-null="true" />
<column name="STATION_NUMBER"
length="5" not-null="true" />
</key>
<one-to-many class="com.valero.retail.rtfa.domain.PosReport" />
</set>

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 2:05 pm 
Beginner
Beginner

Joined: Wed Jul 20, 2005 2:57 pm
Posts: 28
Thank you very much bigbbri!!! It works.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 2:06 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 3:15 pm
Posts: 29
Glad to help!
B

_________________
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.