-->
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: Cascading implementation ?
PostPosted: Thu Aug 30, 2007 11:02 am 
Regular
Regular

Joined: Thu Oct 19, 2006 12:07 pm
Posts: 75
Hi!

Does anyone know where in hibernate is the cascading implemented ?

I look for the part that determines the order of saving of entities, when save() is called for an entity that has associated other entities and cascading is "all".

Example:
Code:
House h;
Address a;
Person p;

a.setHouse(h);
p.setHome(a);

h.getAddresses().add(a);
a.getPeople().add(p);

session.save(a); // saves : h, then a and lastly p
session.close();


So what I need is the code, that gives "a" deterines that "h" is associated and it must be saved before, and also "p" that must be saved after (as it references "a").

Regards,
David


Top
 Profile  
 
 Post subject: Re: Cascading implementation ?
PostPosted: Thu Aug 30, 2007 11:59 am 
Beginner
Beginner

Joined: Mon Aug 27, 2007 8:10 am
Posts: 37
xerces8 wrote:
Hi!

Does anyone know where in hibernate is the cascading implemented ?



In our application we have attributed many-to-many relationship between person and address and one-to-many relationship between person and phone. When we create a new address and link it to a new person, we do enumerate addresses and persit the new of them before persisting the person. Otherwise we are getting exception "save the transient object first".
For phones we do not get this exception - cascade on one-to-many is handled by hibernate.
I do not know why addresses are different in this way, may be we are doing something wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 31, 2007 5:01 am 
Regular
Regular

Joined: Thu Oct 19, 2006 12:07 pm
Posts: 75
is it possible to turn on (or change) cascading setting at runtime ?

Like:
Code:
Session s= ...;
Entity1 e1 = new Entity1("a","foo",bar,e2);

turn_on_save_cascading_for_Entity1();

s.save(e1); // also saves bar and e2, due to cascading

// commit();
// s.close();


How to do turn_on_save_cascading_for_Entity1() that is set cascading "save" (or "all") for all associations of Entity1 ?


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.