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: How to lookup objects from composite foreign keys
PostPosted: Wed Aug 30, 2006 12:00 am 
Newbie

Joined: Thu Aug 10, 2006 10:08 pm
Posts: 12
I am having trouble finding documentation on how to use HQL to lookup values from a composite foregn key.

looking at the mapping document below i have a person class which has a composite id. i want to look up a list of EFTInfo's that are linked to that person.

I can load the person object fine as i have the ID's

How can i lookup the EFTInfos from that point or where would i find this documentation.

should i have some dort of reverse mapping in my person hbm.xml?

Mapping documents:
Code:
   
<class name="EftInfo" table="eft_info">
   <composite-id  name="Id" class="ID">
        <key-property name="Id" column="eft_info_id" type="int" />
        <key-property name="DataBaseID" column="eft_info_db_id" type="int" />
   </composite-id>
   
   <many-to-one class="person" name="person">
      <column name="person_id"/>
      <column name="person_db_id" />
   </many-to-one>
   
   <property name="Description" column="descr" type="AnsiString" length="60" not-null="true"><!-- [descr] [varchar] (60) --></property>

</class>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 7:47 pm 
Newbie

Joined: Thu Aug 10, 2006 10:08 pm
Posts: 12
ok i thought i had found it. The problem is i was hopping to just assign the composite type ID in the HQL (ie. person.ID = ?) but i belive i need to specify right down to the lowest level of the composite foreign Key.

person.Id.ID =? and person.Id.DataBaseID = ?

but i still get an error:

could not resolve property:Id of person [from EftInfo as ei where ei.person.Id.Id = ? and ei.person.Id.DataBaseID = ?]

any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 9:21 am 
Newbie

Joined: Mon Aug 28, 2006 12:47 am
Posts: 6
Location: British Columbia, Canada
I'm fairly new to NHibernate, but I've tried the composite key thing. Why don't you redefine your hbm like so:

<class name="EftInfo" table="eft_info">
<composite-id name="Id" class="ID">
<key-property name="Id" column="eft_info_id" type="int" />
<key-property name="DataBaseID" column="eft_info_db_id" type="int" />
</composite-id>


<property name="Description" column="descr" type="AnsiString" length="60" not-null="true"><!-- [descr] [varchar] (60) --></property>

</class>

with the class:

class EftInfo
{
private int _Id;
private int _dbId;

public int Id
{ get { return _Id; } set { _Id=value; }}

public int DatabaseID
{ get { return _dbId; } set { _dbId=value; }}
}

Then you do:

EftInfo eInfo = new EftInfo()
eInfo.Id = 10;
eInfo.DatabaseID=100;

Avoid the sub-object.


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.