-->
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.  [ 1 post ] 
Author Message
 Post subject: Reporting constraint violations
PostPosted: Fri Apr 27, 2007 9:17 am 
Hey guys,

I was hoping I can get some advice on how to handle the sql constraint violations.
For example, when I save a row in a table with multiple unique constraints, if I get an error for one of the values how can I determine which constraint was violated?
I was hoping that I can somewhat get the constraint name but some of the db's dialects don't support this feature.

i.e. mysql, which I'm using right now, returns something like this:

Code:
WARN  [SocketListener0-9] - JDBCExceptionReporter      - SQL Error: 1062, SQLState: 23000
ERROR [SocketListener0-9] - JDBCExceptionReporter      - Duplicate entry '777' for key 2


I cannot use any of the information available here because mysql may not be the database used in the final product.

Code:
try {
   getSession().saveOrUpdate(entity);
} catch (ConstraintViolationException ce) {
   // ce.getConstraintName() returns null
}



and the constraint name is not available in the exception raised.

One of the ideas was to pre-validate the values but I'm afraid this could be expensive as extra sql statements are executed.

Does anybody have a good strategy for reporting the sql constraint exceptions back to the end user?

Thanks,
Dragos


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.