-->
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.  [ 7 posts ] 
Author Message
 Post subject: I am not able to update a many-to-many relation ship
PostPosted: Thu Apr 07, 2005 11:45 am 
Newbie

Joined: Thu Apr 07, 2005 11:38 am
Posts: 5
Hi all ,

this is the code I am using and I am not able to update the BOMDEFN table...please help I am new to Hibernate.


thanks

-----------------------------------------------------------------------------
ContentObject contentObj = (ContentObject)getHibernateTemplate().load(ContentObject.class, contentObjectOid);

BOMDefn bd = (BOMDefn)getHibernateTemplate().load(BOMDefn.class, new Long("0"));

contentObj.getBoms().add(bd);
getHibernateTemplate().save(contentObj);

----------------------------------------------------------------------------

these are the mappings

<class name="ContentObject" table="Content_Object" discriminator-value="contentObject">
<id name="oid" type="java.lang.Long" column="oid">
<generator class="sequence">
<param name="sequence">Content_Object_Seq</param>
</generator>
</id>

<discriminator column="type"/>

<!-- Entity attributes -->
<property name="name" column="name" type="java.lang.String"/>
<property name="description" type="java.lang.String"/>
<property name="keywords" type="java.lang.String"/>
<property name="contentId" type="java.lang.String"/>
<property name="externalId" type="java.lang.String"/>
<property name="documentType" type="java.lang.String"/>
<property name="bizStatus" type="java.lang.String"/>
<property name="user" type="java.lang.String"/>
<property name="createTimestamp" column="createts" type="java.sql.Timestamp"/>
<property name="modifiedTimestamp" column="modifiedts" type="java.sql.Timestamp"/>

<!-- Entity attributes -->

<!-- Relationships -->
<set name="boms" table="BOMDefn_ContentObject_MM" >
<key column="Content_ObjectOid"/>
<many-to-many column="BOMDefnOid" class="vz.esm.edm.pom.BOMDefn"/>
</set>

</class>


<class name="BOMDefn" table="BOMDefn">
<id name="oid" type="java.lang.Long" column="oid">
<generator class="sequence">
<param name="sequence">BOMDefn_Seq</param>
</generator>
</id>

<!-- Entity attributes -->
<property name="name" type="java.lang.String"/>
<property name="displayName" type="java.lang.String"/>
<property name="requestSystem" type="java.lang.String"/>

<!-- Relationships -->


<set name="contentObjects" table="BOMDefn_ContentObject_MM" >
<key column="BOMDefnOid"/>
<many-to-many column="Content_ObjectOid" class="vz.esm.edm.pom.ContentObject"/>
</set>

</class>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 07, 2005 9:58 pm 
Regular
Regular

Joined: Thu Apr 15, 2004 1:12 pm
Posts: 55
Hi Pradeepbill,

1) It looks like you're trying to implement a bidirectional many-to-many association. Therefore, you need to make sure that you:

(a) map one end of the association with 'inverse="true"';

(b) make sure to add() to the the Collections on both ends of the bidirectional association, not just one end (i.e., just like you would do in regular Java if there were no persistence layer); and

2) Looking at this Java code:

Code:
ContentObject contentObj = (ContentObject)getHibernateTemplate().load(ContentObject.class, contentObjectOid);

BOMDefn bd = (BOMDefn)getHibernateTemplate().load(BOMDefn.class, new Long("0"));

contentObj.getBoms().add(bd);
getHibernateTemplate().save(contentObj);


What is the call to save() supposed to do there? save() is what you call on a transient object to make it persistent. contentObj in this case is already persisitent — you got it from load().

You might think from the names that save() is the opposite of load(), but it's not. delete() is the opposite of save().

cheers,
—ml—


Top
 Profile  
 
 Post subject: what does adding both ends of collection mean
PostPosted: Fri Apr 08, 2005 12:13 am 
Newbie

Joined: Thu Apr 07, 2005 11:38 am
Posts: 5
Hi ml,
thanks for the reply,
what does adding both ends of collection mean? I mean from the code I posted can u give some idea?


thanks in advance

pradeep


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 08, 2005 12:27 am 
Regular
Regular

Joined: Thu Apr 15, 2004 1:12 pm
Posts: 55
Quote:
what does adding both ends of collection mean? I mean from the code I posted can u give some idea?


Hi Pradeep,

It means something along the lines of
Code:
contentObj.getBoms().add(bd);
bd.getContentObjects().add (contentObj);
[/quote]


Top
 Profile  
 
 Post subject: got it ml
PostPosted: Fri Apr 08, 2005 1:03 am 
Newbie

Joined: Thu Apr 07, 2005 11:38 am
Posts: 5
thanks for the instant reply.

pradeep


Top
 Profile  
 
 Post subject: good book for Hibernate
PostPosted: Fri Apr 08, 2005 1:11 am 
Newbie

Joined: Thu Apr 07, 2005 11:38 am
Posts: 5
Hi ml,
can you suggest me a good book , which gives good concepts on the reelationships and other things.?

thanks
Pradeep


Top
 Profile  
 
 Post subject: Re: good book for Hibernate
PostPosted: Fri Apr 08, 2005 10:46 am 
Beginner
Beginner

Joined: Thu Mar 24, 2005 5:21 pm
Posts: 21
pradeepbill wrote:
Hi ml,
can you suggest me a good book , which gives good concepts on the reelationships and other things.?

thanks
Pradeep

The reference documentation for Hibernate is better than most open-source projects.
For further reading, Hibernate In Action is the "bible of Hibernate" (TM). (It's an excellent reference as well). Expect to spend some time soaking in the concepts though - it's not as easy a read as some other books. Some concepts may take a second reading to make clearer sense. Check out: http://www.manning.com/bauer
And if you can afford it or get your employer to pay for it, official training is obviously a great way of getting up to speed as well.
HTH
Satish


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.