Uploaded image for project: 'Hibernate ORM'
  1. HHH-12569

Referential integrity violation on insert when using @OneToOne with @JoinColumn with hibernate.order_inserts=true

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.2.17, 5.3.0.Final
    • Fix Version/s: 5.2.18, 5.3.1
    • Component/s: hibernate-core
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Worked in:
    • Last commented by a user?:
      true
    • Sprint:

      Description

      We have an application that is heavily relying on composite PKs. Among them are two models that share the same PK class and have a @OneToOne relationship declared between them.

      This works fine with Hibernate up to 5.2.13 (including). However, something seems to have broken this onwards because it consistently fails with 5.2.14 and up to 5.2.17.

      Please find the attached example project (Eclipse project with Maven POM) to reproduce the problem.

      Stacktrace with 5.2.17:

      ...
      Caused by: org.hibernate.exception.ConstraintViolationException: could not execute batch
      at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:112)
      at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
      at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.performExecution(BatchingBatch.java:128)
      at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.doExecuteBatch(BatchingBatch.java:104)
      at org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl.execute(AbstractBatchImpl.java:147)
      at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.getBatch(JdbcCoordinatorImpl.java:201)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3006)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3547)
      at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:89)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:600)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:474)
      at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
      at org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:50)
      at org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1398)
      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1483)
      at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1445)
      at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414)
      ... 31 more
      Caused by: org.h2.jdbc.JdbcBatchUpdateException: Referentielle Integrit├Ąt verletzt: "FK5N5TRDO54QQWDACG38752DQ81: PUBLIC.BLOB_STORAGE FOREIGN KEY(FT_ID, IO_ID, LN_CODE, RV_NUMBER, VR_CODE, IOV_NUMBER) REFERENCES PUBLIC.REVISION(FT_ID, IO_ID, LN_CODE, RV_NUMBER, VR_CODE, IOV_NUMBER) ('main', 'yadda', 'en', 1, 'US', 1)"
      Referential integrity constraint violation: "FK5N5TRDO54QQWDACG38752DQ81: PUBLIC.BLOB_STORAGE FOREIGN KEY(FT_ID, IO_ID, LN_CODE, RV_NUMBER, VR_CODE, IOV_NUMBER) REFERENCES PUBLIC.REVISION(FT_ID, IO_ID, LN_CODE, RV_NUMBER, VR_CODE, IOV_NUMBER) ('main', 'yadda', 'en', 1, 'US', 1)"; SQL statement:
      insert into blob_storage (bls_data, ft_id, io_id, ln_code, rv_number, vr_code, iov_number) values (?, ?, ?, ?, ?, ?, ?) [23506-194]
      at org.h2.jdbc.JdbcPreparedStatement.executeBatch(JdbcPreparedStatement.java:1226)
      at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.performExecution(BatchingBatch.java:118)
      ... 45 more

      When you change the Hibernate version in the POM back to 5.2.13, it works as expected.

        Attachments

          Issue links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: