-->
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.  [ 2 posts ] 
Author Message
 Post subject: Newbie: HQL - How to access the "primary keys" ...
PostPosted: Wed Jun 29, 2005 3:26 pm 
Beginner
Beginner

Joined: Wed Nov 17, 2004 11:15 am
Posts: 25
Hi,

I've got a table "Sflight" with 3 primary keys: carrid, connid, fldate.
carrid + connid are foreign keys on "Spfli".

My problem is, that I don't know how to efficiently use the HQL to query for example a single "Sflight" object (when I only have the 3 foreigen-key values for querying).

My hql query string looks like this:
Select sf
from Sflight sf, Spfli sp
WHERE sp.id = sf.id.spfli
AND sp.id.scarr.carrid = :carrid
AND sp.id.connid = :connid
AND sf.id.fldate = :fldate

Since I don't know how to access the primary keys directly from "Sflight", I am also joining "Spfli" to access them. This doesn't seem to be the way to go.

How would a correct HQL query string look like in this case?

Below are corresponding (parts of the) mapping files.

Thanks
Jonny

Hibernate version:3.0.2

Mapping documents:
...
<class name="Sflight" table="sflight">
<composite-id name="id" class="SflightId">
<key-many-to-one name="spfli" class="Spfli">
<column name="carrid" length="5" />
<column name="connid" length="5" />
</key-many-to-one>
<key-property name="fldate" type="date">
<column name="fldate" length="10" />
</key-property>
</composite-id>
...
</class>

...
<class name="Spfli" table="spfli">
<composite-id name="id" class="SpfliId">
<key-many-to-one name="scarr" class="Scarr">
<column name="carrid" length="5" />
</key-many-to-one>
<key-property name="connid" type="string">
<column name="connid" length="5" />
</key-property>
</composite-id>
...
<set name="sflights" inverse="true">
...
</set>
</class>

...
<class name="Scarr" table="scarr">
<id name="carrid" type="string">
<column name="carrid" length="5" />
<generator class="assigned" />
</id>
...
<set name="spflis" inverse="true">
<key>
<column name="carrid" length="5" not-null="true" />
</key>
<one-to-many class="Spfli" />
</set>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2005 3:28 pm 
Beginner
Beginner

Joined: Wed Nov 17, 2004 11:15 am
Posts: 25
Quote:
(when I only have the 3 foreigen-key values for querying)

Must be: when I only have the 3 primary-key values for querying

Sorry
Jonny


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.