-->
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: one-to-one bidirectional association saveorupdate()
PostPosted: Mon May 15, 2006 11:57 pm 
Newbie

Joined: Thu May 04, 2006 11:34 pm
Posts: 6
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0.x

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Quote:
I have created a one-to-one bi directional association using foriegn key between two tables and able to get both the tables fields.

Can anyone help me how the saveorUpdate works with this kind of association.I am setting one object(table) into another using set method and passing the object to save.Only one table is getting updated or saved.
How do I update both the tables.Can anyone give me an example of this

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 12:04 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
try to play with cascade options available on the association.

cascade="save,update"
cascase="all-delete-orphan"
and.......

ex:
<set name="" inverse="true" lazy="true" cascade="all-delete-orphan">


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 10:51 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 5:33 am
Posts: 31
I had this problem a while ago with abidirectional one-to-many mappings.

It seems the only way of doing this is to save both of the objects:

EntityClass1 object1 = new EntityClass1();
EntityClass2 object2 = new EntityClass2();

session.saveOrUpdate( object1 ); // Saves the first object
object2.setTheOtherObject( object1 ); // Sets the relation
session.saveOrUpdate( object2 ); // Save the other object


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.