-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate3: Using <join> element
PostPosted: Wed Jun 15, 2005 7:17 pm 
Regular
Regular

Joined: Fri Mar 26, 2004 11:45 am
Posts: 75
I have some problems figuring out how to use the <join> element in Hibernate3. Suppose I have two tables Person and Addres. Address table has a column Id, and Person has a column AdrsId, which references Id column in the Address table. I am trying to get Hibernate to join Address row with Person row and map the result to an object of the Person class.

I tried:

<class name="Person" table="Person">
<id name="Id" column="Id" />

<join table="Address" >
<key column="Id" />
</join>
</class>

But it generates a query, which joins Person.Id with Address. Id instread of Person.AdrsId and Address.Id

If I do:

<class name="Person" table="Person">
<id name="Id" column="Id" />

<join table="Address" >
<key column="AdrsId" />
</join>
</class>

But it generates a query, which joins Person.Id with Address. AdrsId instread of Person.AdrsId and Address.Id


Do I need to add a many-to-one element inside the join element? If I do, then is there a way to avoid mapping a property inside the Person class to AdrsId column?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 15, 2005 7:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
<key property-ref="..."/> is is not yet possible for <join> in HB3.

Why on earth would you ever want to map address data into the customer class?! Just create an Address class. Much more OO.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 10:54 am 
Regular
Regular

Joined: Fri Mar 26, 2004 11:45 am
Posts: 75
I used a hypothetical example in order to better explain what I needed to do.

In reality we have to change (normalized) the old schema, but don't want to rewrite the HQL queries already written for the old schema. So, we desided to use <join> to map the new tables to the old classes, which will (hopefully) allow us to leave the HQL queries intact.

If I can't use <join>, what are my other alternatives?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 11:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Well, if you have control of the schema, a better relational model would reverse the direction of the FK. Then you can use <join>.

(Unless multiple Person rows can share the same Address row.)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 11:37 am 
Regular
Regular

Joined: Fri Mar 26, 2004 11:45 am
Posts: 75
Yes, multiple persons can share the same address in our new schema.

So, how can we map the new tables to the old classes so that we don't have to change HQL queries?


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