-->
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: Association table not getting updated whe using many-to-many
PostPosted: Fri Dec 30, 2005 12:45 am 
Newbie

Joined: Fri Dec 30, 2005 12:36 am
Posts: 1
Hibernate version:3.0

I have two tables - MEMBER and ACCOUNT, having many-to-many relationship by an association table - MEMBER_ACCOUNT. The database looks like:

MEMBER TABLE:
member_id NUMBER
name VARCHAR(50)

ACCOUNT TABLE:
account_id NUMBER
account_type VARCHAR(20)

MEMBER_ACCOUNT TABLE:
member_account_id NUMBER
member_id NUMBER
account_id NUMBER

I have created two mapping files as follows:
Member.hbm.xml
------------------------------
<id name="memberId" column="MEMBER_ID">
<generator class="sequence">
<param name="sequence">MEMBER_SEQ</param>
</generator>
</id>
<property name="name" type="string" column="NAME"/>
<set name="opportunities" table="MEMBER_OPP" lazy="false" cascade="all-delete-orphan">
<key column="MEMBER_ID" />
<many-to-many column="ACCOUNT_ID" class="com.zenith.hibernate.model.Account" />
</set>

And here is the
Account.hbm.xml
------------------------------------------
<id name="accountId" column="ACCOUNT_ID">
<generator class="sequence">
<param name="sequence">ACCOUNT_SEQ</param>
</generator>
</id>
<property name="type" type="java.lang.String" column="ACCOUNT_TYPE"/>
<set name="member" table="MEMBER_OPP" lazy="false" cascade="all-delete-orphan">
<key column="ACCOUNT_ID" />
<many-to-many column="MEMBER_ID" class="com.zenith.hibernate.model.Member" />
</set>

When I add a new account with members in it, it proprly inserts a new record in both the ACCOUNT and MEMBER tables. But it does not create a row in the association - MEMBER_ACCOUNT table. Apparently there is something I am missing here. Do I need to create a mapping file and a POJO for the association table also??

Appreciate your help.

Thanks
SF


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 3:01 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I'm guessing that hibernate is getting confused because it doesn't know which way the dependencies go. Set inverse="true" for one set, the one which you'd consider dependent (probably account, I'm guessing).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 4:17 pm 
Newbie

Joined: Fri Dec 30, 2005 12:02 am
Posts: 1
tenwit wrote:
I'm guessing that hibernate is getting confused because it doesn't know which way the dependencies go. Set inverse="true" for one set, the one which you'd consider dependent (probably account, I'm guessing).


Tried that out but the same result.. :(


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.