如何在Grails中捕获重复的键异常。当试图为唯一列约束保存现有整数时,在保存/更新记录时会生成错误。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:13265 ERROR 41:13281 ERROR [AbstractFlushingEventListener:324] 无法同步数据库
状态与会话 有机[JDBCExceptionReporter:101]为 键2
23重复条目 '1' .hibernate.exception.ConstraintViolationException:在 org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94) 在 org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66无法 执行JDBC批处理更新) at org.hibernate.jdbc.Abs tractBatcher.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。冲洗(SessionImpl.java:1027)
请您分享解决方案来解决这个问题。
没有,身份证是不是自动生成和列是一个独特的密钥。它是一个输入的文本字段,当用户输入现有的整数时,它将无法保存。这工作正常,但在控制台中,我收到了错误。 – Srinath 2010-04-20 06:00:36