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: ConstraintViolationException when deleting an object
PostPosted: Tue Sep 20, 2005 4:59 pm 
Newbie

Joined: Thu Aug 25, 2005 5:33 pm
Posts: 10
Hi,

when I attempt to delete an object, Hibernate throws a ConstraintViolationException which is expected behaviour due to database referential integrity constraints. However, when I then attempt to refetch this object in the same session via get or load an "ObjectDeletedException: The object with that id was deleted" is thrown. However, if the session is closed and then reopened I can find the object via get or load.

Is the above expected behaviour not being able to get the object after the ConstraintViolationException, or is it a bug?


thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 5:22 pm 
Beginner
Beginner

Joined: Tue Apr 05, 2005 4:27 pm
Posts: 40
Location: canada
if you encounter an exception you should close that session, not performing more operations within it.

Quote:
A HibernateException means your have to rollback your transaction and close the Session. If your Session is coupled to the application; you have to stop the application. Rolling back the database transaction doesn't put your business objects back into the state they were at the start of the transaction. This means the database state and the business objects do get out of sync. Usually this is not a problem, because exceptions are not recoverable and you have to start over after rollback anyway.


from http://www.hibernate.org/168.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 6:47 pm 
Newbie

Joined: Thu Aug 25, 2005 5:33 pm
Posts: 10
Jaime,

Its actually in the transaction.commit() which is throwing the ConstraintViolationException - not the session. Could you point me to where you read that documentation - as the API doco for Session says the session should be closed, but I couldnt find anything relating to closing the session if the transaction throws an exception?

Given the 'open session in view' pattern I wouldnt think we should have to close the session because of this? I'm trying to refetch the object outside of the transaction in the same session.

To me, this problem still smells of a bug???


thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 21, 2005 10:26 am 
Beginner
Beginner

Joined: Tue Apr 05, 2005 4:27 pm
Posts: 40
Location: canada
i already posted the link...

http://www.hibernate.org/168.html

you need to roll back the transacation and close the session...


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.