2011-07-18 191 views
0

我使用休眠,jboss6.0.final和我得到以下异常:重复键值违反唯一约束

ERROR: duplicate key value violates unique constraint "tablename" 
    Detail: Key (pkey)=(11929) already exists. 
2011-07-18 06:28:04,373 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] (http-69.89.2.245-8080-1) 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) [:3.6.0.Final] 
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) [ 

我已经排除从休眠-core.jar添加的jta.jar在我的聚甲醛。 XML。 是什么原因?

回答

0

这个例外是因为你插入了已经存在的bean。

1

您试图插入的记录已存在。您需要使用updatesaveOrUpdate

相关问题