org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

Hibernate JIRA | Rex Madden | 1 decade ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    [HHH-1268] Unidirection OneToMany causes duplicate key entry violation when removing from list - Hibernate JIRA

    atlassian.net | 1 year ago
    org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
  2. 0

    Simple OneToMany parent/child relationship using the default table structure (2 tables and a join table) Add 3 children to the parent. Flush. Remove the first child. Flush throws error: Exception in thread "main" org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:143) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980) at UnidirectionalOneToManyRemoveFromListBug.main(UnidirectionalOneToManyRemoveFromListBug.java:27) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86) Caused by: java.sql.BatchUpdateException: Duplicate key or integrity constraint violation, message from server: "Duplicate entry '5' for key 2" at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1461) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195) ... 11 more The problem is that there is a unique key on the relationship table that gets violated. The session removes the last row in the relationship table, then attempts to rewrite the child_id's. It fails since there is a uniqueness constraint on that column.

    Hibernate JIRA | 1 decade ago | Rex Madden
    org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
  3. 0

    Simple OneToMany parent/child relationship using the default table structure (2 tables and a join table) Add 3 children to the parent. Flush. Remove the first child. Flush throws error: Exception in thread "main" org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:143) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980) at UnidirectionalOneToManyRemoveFromListBug.main(UnidirectionalOneToManyRemoveFromListBug.java:27) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86) Caused by: java.sql.BatchUpdateException: Duplicate key or integrity constraint violation, message from server: "Duplicate entry '5' for key 2" at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1461) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195) ... 11 more The problem is that there is a unique key on the relationship table that gets violated. The session removes the last row in the relationship table, then attempts to rewrite the child_id's. It fails since there is a uniqueness constraint on that column.

    Hibernate JIRA | 1 decade ago | Rex Madden
    org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Get real tick data in AlgoTrader

    Google Groups | 5 years ago | LWL
    org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
  6. 0

    Spring Exception Handling Problem

    Coderanch | 8 years ago | nitin pai
    org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

  1. linxiaolong 2 times, last 1 week ago
  2. mortalman7 32 times, last 9 months ago
9 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.sql.BatchUpdateException

    Duplicate key or integrity constraint violation, message from server: "Duplicate entry '5' for key 2"

    at com.mysql.jdbc.PreparedStatement.executeBatch()
  2. MySQL jdbc
    PreparedStatement.executeBatch
    1. com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1461)
    1 frame
  3. Hibernate
    ActionQueue.executeActions
    1. org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
    2. org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
    3. org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
    4. org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:143)
    4 frames
  4. Hibernate
    SessionImpl.flush
    1. org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
    2. org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    3. org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980)
    3 frames
  5. Unknown
    UnidirectionalOneToManyRemoveFromListBug.main
    1. UnidirectionalOneToManyRemoveFromListBug.main(UnidirectionalOneToManyRemoveFromListBug.java:27)
    1 frame
  6. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    4. java.lang.reflect.Method.invoke(Method.java:585)
    4 frames
  7. IDEA
    AppMain.main
    1. com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)
    1 frame