Hibernate 重复的键值违反了唯一约束

Hibernate 重复的键值违反了唯一约束,hibernate,jboss6.x,Hibernate,Jboss6.x,我使用的是hibernate,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.2

我使用的是hibernate,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) [
我已经从pom.xml中的hibernate-core.jar中排除了jta.jar。
原因是什么?

此异常是因为您插入了已持久化的bean。

您尝试插入的记录已经存在。您需要使用
update
saveOrUpdate