org.hibernate.exception.ConstraintViolationException

If you like a tip written by other Samebug users, mark is as helpful! Marks help our algorithm provide you better solutions and also help other users.
tip

Check if you're not creating unused SQL entities, as it might cause this exception.


rafael

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

  • org.hibernate.test.annotations.entity.BasicHibernateAnnotationsTest ./gradlew hibernate-core:test -Dtest.single=entity/BasicHibernateAnnotationsTest --stacktrace fails on jdk8, passes on jdk7 {noformat} org.hibernate.exception.ConstraintViolationException: could not execute statement at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:129) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:189) at org.hibernate.hql.internal.ast.exec.BasicExecutor.doExecute(BasicExecutor.java:108) at org.hibernate.hql.internal.ast.exec.BasicExecutor.execute(BasicExecutor.java:77) at org.hibernate.hql.internal.ast.exec.DeleteExecutor.execute(DeleteExecutor.java:124) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:415) at org.hibernate.engine.query.spi.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:321) at org.hibernate.internal.SessionImpl.executeUpdate(SessionImpl.java:1215) at org.hibernate.internal.QueryImpl.executeUpdate(QueryImpl.java:116) at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.cleanupTestData(BaseCoreFunctionalTestCase.java:450) at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.afterTest(BaseCoreFunctionalTestCase.java:425) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:36) at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:62) Caused by: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "FK_7CJ956HLMXNL32GWK7EKI7DG4: PUBLIC.NARRATIVE FOREIGN KEY(TOPIC_ID) REFERENCES PUBLIC.TOPIC(ID)"; SQL statement: delete from Topic [23003-145] at org.h2.message.DbException.getJdbcSQLException(DbException.java:327) at org.h2.message.DbException.get(DbException.java:167) at org.h2.message.DbException.get(DbException.java:144) at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:382) at org.h2.constraint.ConstraintReferential.checkRowRefTable(ConstraintReferential.java:399) at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:275) at org.h2.table.Table.fireConstraints(Table.java:803) at org.h2.table.Table.fireAfterRow(Table.java:820) at org.h2.command.dml.Delete.update(Delete.java:80) at org.h2.command.CommandContainer.update(CommandContainer.java:69) at org.h2.command.Command.executeUpdate(Command.java:201) at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:143) at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:129) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:186) ... 18 more {noformat}
    via by Martin Šimka,
  • org.hibernate.test.annotations.entity.BasicHibernateAnnotationsTest ./gradlew hibernate-core:test -Dtest.single=entity/BasicHibernateAnnotationsTest --stacktrace fails on jdk8, passes on jdk7 {noformat} org.hibernate.exception.ConstraintViolationException: could not execute statement at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:129) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:189) at org.hibernate.hql.internal.ast.exec.BasicExecutor.doExecute(BasicExecutor.java:108) at org.hibernate.hql.internal.ast.exec.BasicExecutor.execute(BasicExecutor.java:77) at org.hibernate.hql.internal.ast.exec.DeleteExecutor.execute(DeleteExecutor.java:124) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:415) at org.hibernate.engine.query.spi.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:321) at org.hibernate.internal.SessionImpl.executeUpdate(SessionImpl.java:1215) at org.hibernate.internal.QueryImpl.executeUpdate(QueryImpl.java:116) at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.cleanupTestData(BaseCoreFunctionalTestCase.java:450) at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.afterTest(BaseCoreFunctionalTestCase.java:425) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:36) at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:62) Caused by: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "FK_7CJ956HLMXNL32GWK7EKI7DG4: PUBLIC.NARRATIVE FOREIGN KEY(TOPIC_ID) REFERENCES PUBLIC.TOPIC(ID)"; SQL statement: delete from Topic [23003-145] at org.h2.message.DbException.getJdbcSQLException(DbException.java:327) at org.h2.message.DbException.get(DbException.java:167) at org.h2.message.DbException.get(DbException.java:144) at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:382) at org.h2.constraint.ConstraintReferential.checkRowRefTable(ConstraintReferential.java:399) at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:275) at org.h2.table.Table.fireConstraints(Table.java:803) at org.h2.table.Table.fireAfterRow(Table.java:820) at org.h2.command.dml.Delete.update(Delete.java:80) at org.h2.command.CommandContainer.update(CommandContainer.java:69) at org.h2.command.Command.executeUpdate(Command.java:201) at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:143) at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:129) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:186) ... 18 more {noformat}
    via by Martin Šimka,
    • org.hibernate.exception.ConstraintViolationException: could not execute statement at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:129) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:189) at org.hibernate.hql.internal.ast.exec.BasicExecutor.doExecute(BasicExecutor.java:108) at org.hibernate.hql.internal.ast.exec.BasicExecutor.execute(BasicExecutor.java:77) at org.hibernate.hql.internal.ast.exec.DeleteExecutor.execute(DeleteExecutor.java:124) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:415) at org.hibernate.engine.query.spi.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:321) at org.hibernate.internal.SessionImpl.executeUpdate(SessionImpl.java:1215) at org.hibernate.internal.QueryImpl.executeUpdate(QueryImpl.java:116) at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.cleanupTestData(BaseCoreFunctionalTestCase.java:450) at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.afterTest(BaseCoreFunctionalTestCase.java:425) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:36) at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:62) Caused by: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "FK_7CJ956HLMXNL32GWK7EKI7DG4: PUBLIC.NARRATIVE FOREIGN KEY(TOPIC_ID) REFERENCES PUBLIC.TOPIC(ID)"; SQL statement: delete from Topic [23003-145] at org.h2.message.DbException.getJdbcSQLException(DbException.java:327) at org.h2.message.DbException.get(DbException.java:167) at org.h2.message.DbException.get(DbException.java:144) at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:382) at org.h2.constraint.ConstraintReferential.checkRowRefTable(ConstraintReferential.java:399) at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:275) at org.h2.table.Table.fireConstraints(Table.java:803) at org.h2.table.Table.fireAfterRow(Table.java:820) at org.h2.command.dml.Delete.update(Delete.java:80) at org.h2.command.CommandContainer.update(CommandContainer.java:69) at org.h2.command.Command.executeUpdate(Command.java:201) at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:143) at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:129) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:186) ... 18 more

    Users with the same issue

    tvrmsmith
    23 times, last one,
    Andreas Häber
    1 times, last one,
    Victor_IT
    3 times, last one,
    batwalrus76
    3 times, last one,
    andyglick
    4 times, last one,
    143 more bugmates