org.hibernate.exception.ConstraintViolationException: could not execute statement

Hibernate JIRA | Martin Šimka | 3 years ago
tip
Do you find the tips below useful? Click on the to mark them and say thanks to rafael . Or join the community to write better ones.
  1. 0

    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}

    Hibernate JIRA | 3 years ago | Martin Šimka
    org.hibernate.exception.ConstraintViolationException: could not execute statement
  2. 0

    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}

    Hibernate JIRA | 3 years ago | Martin Šimka
    org.hibernate.exception.ConstraintViolationException: could not execute statement
  3. 0
    samebug tip
    Check if you're not creating unused SQL entities, as it might cause this exception.
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    H2 "OTHER" data type throws Exception when storing String or Boolean

    Stack Overflow | 2 years ago | Steve McLeod
    org.h2.jdbc.JdbcSQLException: Hexadecimal string contains non-hex character: "foobar"; SQL statement: insert into test (key, value) values (?, ?) -- (?1, ?2) [90004-188]
  6. 0

    Unable to generate an api-token on rundeck 1.5

    GitHub | 4 years ago | connaryscott
    org.h2.jdbc.JdbcSQLException: Value too long for column AUTH_ROLES VARCHAR(255) NOT NULL: 'GS-Members-MISMO-CORP,GS-EComm-WebAdmins,GS-WebSiteAccess-MIS-CORP,Web Admins-eCommerce,$MISMO,GS-PrivNAS-AK-CORP,GS-Everyone-M... (303); SQL statement: insert into auth_token (id, version, auth_roles, token, user_id) values (null, ?, ?, ?, ?) [90005-112]
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. 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()
  2. H2 Database Engine
    JdbcPreparedStatement.executeUpdate
    1. org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
    2. org.h2.message.DbException.get(DbException.java:167)
    3. org.h2.message.DbException.get(DbException.java:144)
    4. org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:382)
    5. org.h2.constraint.ConstraintReferential.checkRowRefTable(ConstraintReferential.java:399)
    6. org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:275)
    7. org.h2.table.Table.fireConstraints(Table.java:803)
    8. org.h2.table.Table.fireAfterRow(Table.java:820)
    9. org.h2.command.dml.Delete.update(Delete.java:80)
    10. org.h2.command.CommandContainer.update(CommandContainer.java:69)
    11. org.h2.command.Command.executeUpdate(Command.java:201)
    12. org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:143)
    13. org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:129)
    13 frames
  3. Hibernate
    QueryImpl.executeUpdate
    1. org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:186)
    2. org.hibernate.hql.internal.ast.exec.BasicExecutor.doExecute(BasicExecutor.java:108)
    3. org.hibernate.hql.internal.ast.exec.BasicExecutor.execute(BasicExecutor.java:77)
    4. org.hibernate.hql.internal.ast.exec.DeleteExecutor.execute(DeleteExecutor.java:124)
    5. org.hibernate.hql.internal.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:415)
    6. org.hibernate.engine.query.spi.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:321)
    7. org.hibernate.internal.SessionImpl.executeUpdate(SessionImpl.java:1215)
    8. org.hibernate.internal.QueryImpl.executeUpdate(QueryImpl.java:116)
    8 frames
  4. A Hibernate O/RM Module
    BaseCoreFunctionalTestCase.afterTest
    1. org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.cleanupTestData(BaseCoreFunctionalTestCase.java:450)
    2. org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.afterTest(BaseCoreFunctionalTestCase.java:425)
    2 frames
  5. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    4. java.lang.reflect.Method.invoke(Method.java:483)
    4 frames
  6. JUnit
    FailOnTimeout$StatementThread.run
    1. org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    2. org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    3. org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    4. org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:36)
    5. org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:62)
    5 frames