-->
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.  [ 4 posts ] 
Author Message
 Post subject: NonUniqueObjectException and cascade all-delete-orphan
PostPosted: Wed Aug 10, 2005 4:44 am 
Beginner
Beginner

Joined: Sun Sep 19, 2004 5:02 pm
Posts: 28
Location: Poland
I have collection mapped with cascade = "all-delete-orphan".

I remove some object from this collection.

Then I create another one with the same primary key as the one removed and add this object to collection.

When I commit this transaction NonUniqueObjectException is thrown.

_________________
Lmichasz


Top
 Profile  
 
 Post subject: Re: NonUniqueObjectException and cascade all-delete-orphan
PostPosted: Wed Aug 10, 2005 4:26 pm 
Beginner
Beginner

Joined: Thu Feb 17, 2005 9:20 pm
Posts: 36
Location: Vancouver, WA
Lmichasz wrote:
I have collection mapped with cascade = "all-delete-orphan".

I remove some object from this collection.

Then I create another one with the same primary key as the one removed and add this object to collection.

When I commit this transaction NonUniqueObjectException is thrown.


With this cascade option Hibernate keeps tracking changes to collection and to instances of objects loaded in the same transaction until transaction gets commited and session closed. Your previously loaded instance after deletion from collection was marked as deleted and will be deleted from DB if you save parent and commit transaction. Your new object will be as a new for Hibernate. Hibernate not smart enough to determine that actually you are trying to execute update (and/or delete and insert) Reuse your instance if your are not going to delete it. Or, create a new one with different ID.

_________________
Vasyl Zhabko


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 5:34 pm 
Beginner
Beginner

Joined: Sun Sep 19, 2004 5:02 pm
Posts: 28
Location: Poland
I suppose this is some bug that can be fixed.

In hibernate all database changes are executed in this order: insert, update, delete.

This problem araises because deletes are after inserts.

When I call flush before adding new object to collection transaction complets sucessfull.

I know that Hibernate detects this kind of situation when I use explicite delete and save - then flush is automaticaly invoked in save method before inserting new object when there is another one with the same id that is marked as deleted.

Unfortunatly for collection this doesn't work. Isn't it possible to fix this?

_________________
Lmichasz


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 5:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No.


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