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

Persist of detached entity in derived ID

    Details

    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

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

      Description

      When a @ManyToOne relation is present on a composite key, Hibernate tries to persist that object even if no persist operation is done on the parent entity. This cause PersistentObjectException when an entity is retrieved from cache and Hibernate tries to persist its detached @ManyToOne key.

      For example:

      @Entity
      @IdClass(MyBeanId.class)
      public class MyBean {
      
          @Id
          @ManyToOne
          private MyOtherBean other;
      
          @Id
          private Long id;
      
      }
      

      A first query.getSingleResult() works, but all subsequent ones throw this:

      Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: MyOtherBean
      	at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:124)
      	at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:58)
      	at org.hibernate.tuple.entity.AbstractEntityTuplizer$IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller.getIdentifier(AbstractEntityTuplizer.java:384)
      	at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:219)
      	at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:4633)
      	at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:4344)
      	at org.hibernate.engine.internal.ForeignKeys.isTransient(ForeignKeys.java:226)
      	at org.hibernate.engine.internal.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:276)
      	at org.hibernate.type.EntityType.getIdentifier(EntityType.java:455)
      	at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:153)
      	at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:52)
      	at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:627)
      	at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1943)
      	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1896)
      	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1874)
      	at org.hibernate.loader.Loader.doQuery(Loader.java:919)
      	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336)
      	at org.hibernate.loader.Loader.doList(Loader.java:2610)
      	at org.hibernate.loader.Loader.doList(Loader.java:2593)
      	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2422)
      	at org.hibernate.loader.Loader.list(Loader.java:2417)
      	at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:501)
      	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371)
      	at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216)
      	at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1339)
      	at org.hibernate.internal.QueryImpl.list(QueryImpl.java:87)
      	at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:606)
      	at org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:529)
      	... 122 more
      

        Attachments

          Issue links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: