【发布时间】:2010-04-20 04:35:11
【问题描述】:
如何在 Grails 中捕获重复的键异常。尝试为唯一列约束保存现有整数时,在保存/更新记录时会生成错误。
也用过
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
}
但无法捕捉到这个问题。
23:41:13,265 错误 [JDBCExceptionReporter:101] 重复条目“1” 关键 2
23:41:13,281 错误 [AbstractFlushingEventListener:324] 无法将数据库
状态与会话同步 org.hibernate.exception.ConstraintViolationException:不能 执行 JDBC 批量更新 org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94) 在 org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) 在 org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275) 在 org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266) 在 org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168) 在 org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) 在 org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50) 在 org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
你能分享一下解决这个问题的方法吗?
【问题讨论】:
标签: grails