-->
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: all-delete-orphan order of execution (unique constrain)
PostPosted: Mon Mar 26, 2007 9:04 am 
Newbie

Joined: Mon Mar 26, 2007 8:43 am
Posts: 2
Hi

I run the following code (in a transaction) for a collection with all-delete-orphan:

Code:
parent.getChildren().clear();
parent.add(child1);
parent.add(child2);
parent.add(child3);



Code:
class Parent{
Integer id;
Set children;
...
}


class Child{
Integer id;
String someUniqueProp;
...
}



on Child.someUniqueProp I have a DB unique constrain
also the property is mapped as unique='true' in the mapping file

before the call to parent.getChildren().clear() the parent contained a chiled with someUniqueProp="X" (persistent)

child1 that is added after the call to clear, also contains someUniqueProp="X"

when I run the above code (psaudo code) I get an exception (unique constrain vilation)

does hibernate first add the new children and only then delete orphans?
to check it I tried:

Code:
parent.getChildren().clear();
// force delete of orphans
session.flush()

// continue adding children
parent.add(child1);
parent.add(child2);
parent.add(child3);



now the unique constrain violation doesn't happen

since I will get this object as a detached object with no ability to call flush after the call to clear(), is there any other way to make sure all-delete-orphan will first delete orphans and only then add the new children?

I can force uniqueness in code but this is unacceptable by the design

any other way to have a detached object with all-delete-orphan and a unique constrain?

Thanks

Ehrann


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 12, 2007 11:31 am 
Newbie

Joined: Tue Mar 13, 2007 10:36 am
Posts: 5
Hi,

I am facing exactly the same problem and cannot use flush as I am using detached object.

How did you solve the problem? Please let me know.


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.