-->
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: lines aren't deleted when document is updated?
PostPosted: Tue Jul 31, 2007 4:10 am 
Newbie

Joined: Sat Apr 07, 2007 6:53 am
Posts: 16
What about objects that has been removed from collection and parent is updated?

I execute this code:

document.lines.Add(new line(0,...))
document.lines.Add(new line(1,...))
document.lines.Add(new line(2,...))
document.lines.Add(new line(3,...))
session.saveOrUpdate(document);


later...

document.remove_line(line) -->
line.Document = null;
this.lines.remove(line);
session.SaveOrUpdate(document);

SQL generated-->
UPDATE DOCUMENT...
UPDATE LINE ... WHERE LINE = 0;
UPDATE LINE ... WHERE LINE = 1;
UPDATE LINE ... WHERE LINE = 3;
However line number 2 isn't deleted from database.

Mappings-->


Quote:

Document-->
<set name="Linies" cascade="all-delete-orphan" inverse="true" lazy="false">
<key column="EXPEDICIO"/>
<one-to-many class="Model.Linia_Expedicio, Model"/>
</set>

Lines-->
<composite-id name="Codi" class="Model.Linia_Expedicio_PK">
<key-many-to-one name="Expedicio" class="Model.Expedicio" column="EXPEDICIO" lazy="false"/>
<key-property name="Linia" column="LINIA" type="Int32"/>
</composite-id>


What's wrong?
Thansk for all.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 31, 2007 12:31 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
I don't think its wise to do this:
line.Document = null;
because document is part of the primary key of your line item. In my simple test case I get an exception if I set the parent element to null inside the transaction after removing it from the collection.


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.