-->
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.  [ 1 post ] 
Author Message
 Post subject: Composite key mapping w/ hibernate v3.2.6 and jdk-6
PostPosted: Tue Jan 04, 2011 1:37 pm 
Newbie

Joined: Wed Mar 14, 2007 2:14 pm
Posts: 8
Hi,
I have problem to map a relationship table with both regular and composite foreign keys in it. Here is the details:

Assume we have three tables:
social_site(id, site_url)
user(first_name, last_name, birth_day, gender). The PK is composite of first_name and last_name
has_friend(social_site_id, user_first_name, user_last_name, friend_first_name, friend_last_name)

Here, the has_friend table defines relationship beteen users for a given social site which basically has three foreign keys:
FK1. social_site_id refers to social_site(id)
FK2/CompositeKey (user_first_name, user_last_name) refers to user(first_name, last_name)
FK3/CompositeKey (friend_first_name, friend_last_name) refers to user(first_name, last_name)

But my following basic mapping is not working for a simple load() call in which I did not see any SQL generated and the result var "expected" only contains the query instance's id.

So anything wrong with my mapping here?

Note, (1) I have equals and hashCode and Serializable implemented for HasFriend classes.
(2) For User class mapping(source code not shown here), I used a UserID class to define the composite-id with both firstName and lastName and load() call works fine for a given first and last name.

Thanks for the help
-Herbert

============================================================================
<hibernate-mapping>
<class name="HasFriend" table="has_friend">
<composite-id>
<key-many-to-one name="socialSite" class="SocialSite" column="social_site_id"/>

<key-many-to-one name="user" class="User">
<column name="user_first_name"/>
<column name="user_last_name"/>
</key-many-to-one>

<key-many-to-one name="friend" class="User">
<column name="friend_first_name"/>
<column name="friend_last_name"/>
</key-many-to-one>

</composite-id>

</class>

</hibernate-mapping>

Simple query

SocialSite queryPara1 = new SocialSite();
queryPart1.setId(100);
User queryPara2 = new user();
queryPara2.setFirstName("John");
queryPara2.setLastName("Doe");
User queryPara3 = new user();
queryPara3.setFirstName("Jane");
queryPara3.setLastName("Doe");

HasFriend queryInstance = new HasFriend();
queryInstance.setSocialSite(queryPara1);
queryInstance.setUser(queryPara2);
queryInstance.setFriend(queryPara3);

HasFriend expected = getHibernateTemplate().load(HasFriend.class, queryInstance);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.