-->
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: version+integrity constraint violation
PostPosted: Wed Apr 19, 2006 5:28 pm 
Newbie

Joined: Sun Apr 09, 2006 8:38 am
Posts: 14
Hi,

I am trying to add versioning to my classes, in order to support
optimistic locking. I have encountered the following problem:

what I'm doing is this:
1. clean DB
2. insert entity with id=123
3. other stuff.
4. delete the entity with id 123 (this is through hibernate! session sould be aware of the deletion!)
5. try to insert an entity with id 123.

at the last stage, I get an exception regarding integrity constraint violation.
note that there is no entity with the same ID in the DB.

This only happened once I added the versioning to my classes.
can this be a situation where the session still "remembers" the entity from step 2, even though I deleted it from the DB (using delete())?

what am I doing wrong?

Thanks in advance,

Assaf.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 7:13 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 2:26 pm
Posts: 28
Try calling Session.flush() between steps 4 and 5.

From the reference manual:

Quote:
From time to time the Session will execute the SQL statements needed to synchronize the JDBC connection's state with the state of objects held in memory. This process, flush, occurs by default at the following points

* from some invocations of find() or iterate()
* from net.sf.hibernate.Transaction.commit()
* from Session.flush()

The SQL statements are issued in the following order

1. all entity insertions, in the same order the corresponding objects were saved using Session.save()
2. all entity updates
3. all collection deletions
4. all collection element deletions, updates and insertions
5. all collection insertions
6. all entity deletions, in the same order the corresponding objects were deleted using Session.delete()


It could be that step 2 has been flushed to the database, but step 4 hasn't. Then steps 4 and 5 will be flushed together, and according to the documentation the INSERT will be done first.


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.