-->
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.  [ 3 posts ] 
Author Message
 Post subject: ConstraintVoilationException Handling
PostPosted: Thu Apr 21, 2005 6:38 pm 
Newbie

Joined: Thu Apr 21, 2005 6:28 pm
Posts: 1
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.7

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using: DB2 8.0

The generated SQL (show_sql=true): true

Debug level Hibernate log excerpt:

Code:

try
{
beginTransaction();
try
{
    getSessionManager().save(ABCDO);
}
catch(HibernateException he)
{

    //call the update in case of constraintVoilationException
    getSessionManager().update(ABCDO);
}
commitTransaction();

}
catch(HibernateException he)
{

}
finally
{
   closeSession();
}


it throws the ConstraintVoilationException during the commitTransaction() but not during the save call

is there way to catch ConstraintVoilationException during the save call itself


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 21, 2005 6:42 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
What you do will not work in any case. If a Session throws an exception it has to be discarded, not re-used. Read the section about exceptions again in the reference documentation. No, you can't use database exceptions for data validation.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 25, 2005 8:28 am 
Beginner
Beginner

Joined: Wed Feb 23, 2005 11:32 am
Posts: 25
Location: Austria/Vienna
>> What you do will not work in any case. If a Session throws an exception it >> has to be discarded, not re-used. Read the section about exceptions
>> again in the reference documentation. No, you can't use database
>> exceptions for data validation.


we have also the fact, that it is possible to get a constraint violation during runtime due to optimistic locking.

is it possible to discard the session and create a new one, while we operate within a CMT-Transaction ?

it would be nececcary to close the existing session, create a new one which will be the one with a possible constraint violation, because we do not like to throw away all statements that was done in the business transaction so far ... ?

cgs


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