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

Merging of new entities can fail depending on cascade order

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.1.10, 5.1.12
    • Fix Version/s: 5.2.17, 5.3.0.CR2, 5.1.14
    • Component/s: hibernate-core
    • Labels:
      None
    • Environment:
      This occurs with Hibernate 5.1.10 on Wildfly 12 as well as with Hibernate 5.1.12 on JBoss EAP 7.1.1.
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

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

      Description

      Depending on the initialization order of entities a cascaded merge is failing with an IllegalStateException like:

      08:26:15,502 ERROR [org.jboss.as.ejb3.invocation] (default task-1) WFLYEJB0034: EJB Invocation failed on component Bean for method public abstract void org.jboss.playground.BeanRemote.errorTest(java.lang.Long,java.lang.String): javax.ejb.EJBException: java.lang.IllegalStateException: MergeContext#attempt to create managed -> managed mapping with different entities: [org.jboss.playground.Frd#9]; [org.jboss.playground.Frd#9]
      	at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:186)
      	at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275)
      	at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:330)
      	at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:238)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:509)
      	at org.jboss.weld.module.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:81)
      	at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:89)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.as.ejb3.remote.EJBRemoteTransactionPropagatingInterceptor.processInvocation(EJBRemoteTransactionPropagatingInterceptor.java:89)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:47)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:100)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.as.ejb3.deployment.processors.StartupAwaitInterceptor.processInvocation(StartupAwaitInterceptor.java:22)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.as.ejb3.deployment.processors.EjbSuspendInterceptor.processInvocation(EjbSuspendInterceptor.java:57)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:67)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:54)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:60)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:438)
      	at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:619)
      	at org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:57)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:53)
      	at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:198)
      	at org.wildfly.security.auth.server.SecurityIdentity.runAsFunctionEx(SecurityIdentity.java:380)
      	at org.jboss.as.ejb3.remote.AssociationImpl.invokeWithIdentity(AssociationImpl.java:541)
      	at org.jboss.as.ejb3.remote.AssociationImpl.invokeMethod(AssociationImpl.java:536)
      	at org.jboss.as.ejb3.remote.AssociationImpl.lambda$receiveInvocationRequest$0(AssociationImpl.java:194)
      	at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
      	at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
      	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
      	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
      	at java.lang.Thread.run(Thread.java:748)
      Caused by: java.lang.IllegalStateException: MergeContext#attempt to create managed -> managed mapping with different entities: [org.jboss.playground.Frd#9]; [org.jboss.playground.Frd#9]
      	at org.hibernate.event.internal.MergeContext.put(MergeContext.java:239)
      	at org.hibernate.event.internal.DefaultMergeEventListener.entityIsPersistent(DefaultMergeEventListener.java:199)
      	at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:175)
      	at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:853)
      	at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:835)
      	at org.hibernate.engine.spi.CascadingActions$6.cascade(CascadingActions.java:260)
      	at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:423)
      	at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:348)
      	at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:187)
      	at org.hibernate.engine.internal.Cascade.cascadeCollectionElements(Cascade.java:456)
      	at org.hibernate.engine.internal.Cascade.cascadeCollection(Cascade.java:388)
      	at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:351)
      	at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:187)
      	at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:136)
      	at org.hibernate.event.internal.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:460)
      	at org.hibernate.event.internal.DefaultMergeEventListener.entityIsPersistent(DefaultMergeEventListener.java:201)
      	at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:175)
      	at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:853)
      	at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:835)
      	at org.hibernate.engine.spi.CascadingActions$6.cascade(CascadingActions.java:260)
      	at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:423)
      	at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:348)
      	at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:187)
      	at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:136)
      	at org.hibernate.event.internal.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:460)
      	at org.hibernate.event.internal.DefaultMergeEventListener.entityIsPersistent(DefaultMergeEventListener.java:201)
      	at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:175)
      	at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:853)
      	at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:835)
      	at org.hibernate.engine.spi.CascadingActions$6.cascade(CascadingActions.java:260)
      	at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:423)
      	at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:348)
      	at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:187)
      	at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:136)
      	at org.hibernate.event.internal.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:460)
      	at org.hibernate.event.internal.DefaultMergeEventListener.entityIsPersistent(DefaultMergeEventListener.java:201)
      	at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:175)
      	at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:68)
      	at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:843)
      	at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:825)
      	at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:830)
      	at org.hibernate.jpa.spi.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:1161)
      	at org.jboss.as.jpa.container.AbstractEntityManager.merge(AbstractEntityManager.java:565)
      	at org.jboss.playground.Bean.errorTest(Bean.java:64)
      	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.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:509)
      	at org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:90)
      	at org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:101)
      	at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:40)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:53)
      	at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:52)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51)
      	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
      	at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:273)
      	... 44 more
      

      The attached project HHH-12439.zip can be used to reproduce the issue.

      Steps to reproduce the Issue:

      1.) Build the attached project using Maven
      2.) Install Wildfly 12
      3.) Copy the build module:
      cp -a $PROJECT_ROOT/playground-module/target/jboss-modules/org/ $JBOSS_HOME/modules/
      4.) Copy the build application:
      cp $PROJECT_ROOT/playground-app/ear/target/playground-app.ear $JBOSS_HOME/standalone/deployments/
      5.) Start the server
      6.) Run the client application using Maven:
      mvn -f playground-app/client/pom.xml exec:exec

        Attachments

          Issue links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: