-->
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: Can <join> work for me ?
PostPosted: Wed Sep 14, 2005 4:46 am 
Newbie

Joined: Wed Sep 14, 2005 4:09 am
Posts: 2
Hibernate version: Hibernate 3.0.5

In a <join> can you specify the property from the parent table that should be used in the join ? It seems to default to the <id> of the parent table.

Example :

The tables are

Code:

STUFF      
------------------
STUFF_ID
STUFF_NAME
STUFF_CAT_ID
------------------

CATEGORY
------------------
CAT_ID
CAT_NAME
------------------


Now I have a class called Stuff :

Code:
class Stuff
{
   private Long stuffID;
   private String stuffName;
   private String categoryName;
}


and in the mapping I have :

Code:
<class name="Stuff" table="STUFF" lazy="false" mutable="true">
   <id name="stuffID" column="STUFF_ID"/>
   <property name="stuffName" column="STUFF_NAME"/>
   <join table="CATEGORY">
      <key column="CAT_ID" />
      <property name="categoryName" column="CAT_NAME" />
   </join>
</class>

This tries to join STUFF.STUFF_ID with CATEGORY.CAT_ID. Is there any way to make it use STUFF.STUFF_CAT_ID instead ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 4:57 am 
Pro
Pro

Joined: Fri Sep 02, 2005 4:21 am
Posts: 206
Location: Vienna
This is possible, as long as STUFF_CAT_ID is a unique index.

Using property-ref allows to do things like that.

My advice: take a look at the documentation on property-ref, and if you're still unsure how it works, post again :-)

Erik


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 5:27 am 
Newbie

Joined: Wed Sep 14, 2005 4:09 am
Posts: 2
In my case there can be many Stuff having the same Category and hence the the same STUFF_CAT_ID. Is there any way around ?


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.