-->
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.  [ 2 posts ] 
Author Message
 Post subject: hibernate list collection cascade auto?
PostPosted: Mon Apr 10, 2006 10:47 pm 
Newbie

Joined: Mon Feb 21, 2005 12:21 am
Posts: 2
my demo hbm:


<class name="Customer" table="Customer" lazy="true">
<id name="customereID" type="int" ....>
<generator class="native" />
</id>
<property name="name" type="string" ..../>

<list name="phoneNumbers" lazy="true" table="CusPhone">
<key column="CustomerID"/>
<list-index column="PhoneIndex"/>
<element type="string" column="PhoneNumber" not-null="true"/>
</list>
</class>

this hbm don't set "cascade" property, so it's "none"

.......
Customer tom = new Customer();
tom.addPhone("1");
tom.addPhone("2");
.....
session.merge(tom);
......

I think this just save tom in Customer table(without CusPhone table),
but CusPhone also saved actually.

is anyone can explain this?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 10, 2006 11:52 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The cascade attribute determines whether or not changes to associated objects are flushed when a base object is changed/flushed. There are no associated objects in your mapping: elements are values, not entities. The list isn't inverse="true", so it is part of Customer: it is not an associated object, so cascade doesn't apply to it. In fact, because this is a list of values (not entities), it can't be declared inverse="true" (or at least, it can't usefully be declared inverse="true").

If the list contained entities instead of elements, then changing a value in one of the entities would not cause the relevant DB row to be updated when the parent entity is flushed. That is what the cascade="none" does. So if you want the phone numbers to not cascade, you'll have to model the CusPhone table as a separate class, instead of using element.


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