org.hibernate.exception.ConstraintViolationException

could not insert: [Testtable]

Samebug tips0

We couldn't find tips for this exception.

Don't give up yet. Paste your full stack trace to get a solution.

Solutions on the web573

  • via Unknown by AndyW,
  • via Unknown by AndyW,
  • via Unknown by 843859,
  • Stack trace

    • org.hibernate.exception.ConstraintViolationException: could not insert: [Testtable] at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:74) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1859) at org.hibernate.persister.entity.BasicEntityPersister.updateOrInsert(BasicEntityPersister.java:1906) at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:2139) at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:75) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:726) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:320) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86) at HibernateTest.main(HibernateTest.java:38) Caused by: java.sql.SQLException: Duplicate key or integrity constraint violation message from server: "Duplicate entry '2' for key 1" at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2001) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1168) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1279) at com.mysql.jdbc.Connection.execSQL(Connection.java:2281) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1825) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1667) at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1846) ... 12 more

    Write tip

    You have a different solution? A short tip here would help you and many other users who saw this issue last week.

    Users with the same issue

    Unknown visitor
    Unknown visitorOnce,
    AxeloAxelo
    3 times, last one
    rocdayrocday
    Once,
    slashslash
    Once,
    zbalintzbalint
    2 times, last one
    42 more bugmates