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);
|