Grails Duplicate Exception handling

Posted by Srinath on Stack Overflow See other posts from Stack Overflow or by Srinath
Published on 2010-04-20T04:35:11Z Indexed on 2010/04/20 4:43 UTC
Read the original article Hit count: 312

Filed under:

Hi,

How to catch duplicate key exceptions in Grails . when trying to save existing integer for a unique column constraint, the error is generating while saving/updating a record .

Also used
try{
object.save(flush:true)
}catch(org.springframework.
dao.DataIntegrityViolationException e){
println e.message
}catch(org.hibernate.exception.ConstraintViolationException ex){
println e.message
}catch(Exception e){
println e.message
}

But unable to catch this issue .

23:41:13,265 ERROR [JDBCExceptionReporter:101] Duplicate entry '1' for key 2
23:41:13,281 ERROR [AbstractFlushingEventListener:324] Could not synchronize database
state with session org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)

Could you please share the solution to solve this .

© Stack Overflow or respective owner

Related posts about grails