-->
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: more precise exception when insert fails?
PostPosted: Wed Aug 02, 2006 11:39 am 
Newbie

Joined: Wed Aug 02, 2006 11:30 am
Posts: 7
When attempting to insert a record (save an object) which has a unique constraint on a column, and the unique constraint is being violated, I receive this exception:

org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update

Is it possible for hibernate to provide a more useful/specific exception, so I can interpret what the actual problem was?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 11:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you probably have to disable jdbc batching to get a meaningfull exception from the database.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 11:51 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
I just use following code to try to get the reason for exception and then throw my application exception based on it. I remember here, months back, on this forum there was an example to find the exact cause of exception - but I am not able to find the link/post.

Code:
String exMsg = e.getMessage();
System.out.println("exceptionMessage = " + exMsg);
// Will this naming convention stay same
// for all future releases of hibernate?
if ( (exMsg != null) && (exMsg.indexOf( "org.hibernate.exception.ConstraintViolationException" ) != -1) ) {
   exMsg = "The Code entered already exists, please enter a unique Code.";
}
throw new MyApplicationException( exMsg );


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 12:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes, but it probably still requires disable jdbc batching to get those exceptions.

_________________
Max
Don't forget to rate


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.