varsha
varsha

Reputation: 314

Duplicate key value violates unique constraint

I am using hibernate, jboss6.0.final and I am getting following exception:

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) [

I have excluded the jta.jar from hibernate-core.jar in my pom.xml. What is the reason?

Upvotes: 0

Views: 3895

Answers (2)

carlspring
carlspring

Reputation: 32567

The record you're trying to insert already exists. You need to use update or saveOrUpdate.

Upvotes: 1

Zemzela
Zemzela

Reputation: 3080

This exception is because you insert already persisted bean.

Upvotes: 0

Related Questions