-->
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.  [ 8 posts ] 
Author Message
 Post subject: unique constraint error
PostPosted: Mon Jan 29, 2007 6:07 am 
Beginner
Beginner

Joined: Tue Dec 19, 2006 12:55 pm
Posts: 27
Hi all,

I have the following problem:

· I have a table with a unique constraint on a pair of columns, let's call them (X, Y). I start a transaction with hibernate in which i first delete some rows and then i insert new ones. These new rows have the same values for (X, Y) than the old ones, but new values for other columns, also i use new Java Objects to be inserted on the table (with the PK attribute set to null), but despite of this i get an unique constraint error when the transaction ends and tries to commit. Suggestions? Any help would be appreciated.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 6:45 am 
Newbie

Joined: Tue Dec 12, 2006 3:19 am
Posts: 17
Location: Spain
Hello
Do you commit (flush) the session between delete and insert?
http://www.hibernate.org/hib_docs/v3/re ... e-flushing

Code:
DELETE
commit
INSERT
commit


Last edited by i92absaj on Mon Jan 29, 2007 10:05 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 7:07 am 
Beginner
Beginner

Joined: Tue Dec 19, 2006 12:55 pm
Posts: 27
Hi man,

Thxs for your help, i don't commit between delete and insert,
the transaction should be committed only at the end, am i wrong?.
I don't do that, but i have a session.setFlushMode(FlushMode.AUTO)
at the beginning of the transaction, previous to the deletes and the inserts, don't know if this could be the problem.

Thxs in advance


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 8:06 am 
Newbie

Joined: Mon Aug 15, 2005 10:02 am
Posts: 7
In the doc the algorithm to executing flush (in this case the auto-flush) says that insertions come first. I'm not 100% shure but I think you'll have to call session.flush() between the operations. It only says that hibernate will have to make things reflected in the database before doing other operations and will not commit your transcation.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 8:19 am 
Beginner
Beginner

Joined: Tue Dec 19, 2006 12:55 pm
Posts: 27
I can´t test that right now, but i will try it in a few hours, i´ll tell you if that is the solution of the problem

Thxs all of you


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 1:03 pm 
Beginner
Beginner

Joined: Tue Dec 19, 2006 12:55 pm
Posts: 27
Hi Eugenio, I tested it: delete - flush - insert and it works, thxs for your help, i don't understand well why we have to be aware of using
the flush method, i think that should be hibernate business. Anyway thxs again.

See you.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 30, 2007 3:02 am 
Newbie

Joined: Tue Dec 12, 2006 3:19 am
Posts: 17
Location: Spain
I'm glad for you


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 30, 2007 10:11 am 
Beginner
Beginner

Joined: Tue Dec 19, 2006 12:55 pm
Posts: 27
I`ve just realized that you told me the same as Eugenio, thxs both of you

See you


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