-->
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: Association of two tables using composite key
PostPosted: Fri Sep 12, 2008 2:58 pm 
Newbie

Joined: Fri Sep 12, 2008 2:10 pm
Posts: 2
Hi,
I need the solution for the following.

Thank you in advance.

Problem Description
-------------------
I have two tables

User and a Group

In User table the composite key is (cid, groupid, userid)

In Group table the composite key is (cid, groupid)

The (cid, groupid) part of Users' composite key refers the key in Group table

The query to be generated using the association is

select u.cid,u.userid,u.groupid,g.groupname,g.groupdesc from User u, Group g
where u.cid = g.cid and u.groupid = g.groupid;


The hbm files for both the tables is as follows
There is difficulty in providing association for these two tables in the hbm files.
Can any one please help me in this?



Group
-------
<hibernate-mapping default-cascade="none" default-access="property" default-lazy="true" auto-import="true">

<class name="report.bean.user.detail.Group" table="Group">

<composite-id name="GroupKey" class="report.bean.user.detail.GroupId">
<key-property name="cId" />
<key-property name="GroupId"/>
</composite-id>

<property name="GroupName"/>
<property name="GroupDescription"/>

</class>
</hibernate-mapping>


USER
-------
<hibernate-mapping default-cascade="none" default-access="property" default-lazy="true" auto-import="true">
<class name="report.bean.user.detail.User" table="USER">

<composite-id>
<key-property name="cid"/>
<key-property name="GroupId"/>
<key-property name="userId"/>
</composite-id>

<property name="firstname"/>
<property name="lastname"/>

</class>

</hibernate-mapping>



Providing solution for the above is greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2008 3:09 pm 
Newbie

Joined: Wed Sep 03, 2008 10:17 am
Posts: 4
Something like this should work. Add it to your Group.hbm

<set name="userDetails" lazy="false">
<key>
<column name="GroupId" />
<column name="userId" />
</key>
<one-to-many class="report.bean.user.detail.User" />
</set>

Also, in Hibernate reference manual, section 24.4.3 has a very similar example to what you are trying to achieve. Good luck.


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.