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

Cascade primary key with @Mapsid on @OneToOne is not working

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 5.2.2
    • Fix Version/s: None
    • Component/s: hibernate-core
    • Labels:
    • Environment:
      OSX 10.12.4
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true

      Description

      In my setup I have an unidirectional one-to-one relation from Person -> Address in the attach test case. The Person has @EmbeddedId which one of it's id's should be cascaded to the Address id.

      When I map a @OneToOne relation with @Mapsid with the purpose of cascade the primary key it throw an exception.

      If I have read the JPA 2.1 specification correctly it should be supported?

      I have attached test in the `ORMUnitTestCase` file

      javax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned beforeQuery calling save(): org.hibernate.bugs.ORMUnitTestCase$Address
      
      	at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147)
      	at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
      	at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
      	at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:769)
      	at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:742)
      	at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:747)
      	at org.hibernate.bugs.ORMUnitTestCase.insertTestData(ORMUnitTestCase.java:118)
      	at org.hibernate.bugs.ORMUnitTestCase.hhh11303Test(ORMUnitTestCase.java:93)
      	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:498)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
      	at org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:45)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      	at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:74)
      Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned beforeQuery calling save(): org.hibernate.bugs.ORMUnitTestCase$Address
      	at org.hibernate.id.Assigned.generate(Assigned.java:33)
      	at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:105)
      	at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
      	at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
      	at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
      	at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
      	at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
      	at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:673)
      	at org.hibernate.internal.SessionImpl.save(SessionImpl.java:665)
      	at org.hibernate.id.ForeignGenerator.generate(ForeignGenerator.java:108)
      	at org.hibernate.mapping.Component$ValueGenerationPlan.execute(Component.java:418)
      	at org.hibernate.id.CompositeNestedGeneratedValueGenerator.generate(CompositeNestedGeneratedValueGenerator.java:97)
      	at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:105)
      	at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:189)
      	at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:132)
      	at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:58)
      	at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:762)
      	... 16 more
      

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:

                Stride room