PAGS group Import error 'IllegalStateException: Multiple representations of the same entity are being merged'

Description

There seems to be a bug that prevents importing PAGS groups where certain types of parent/child relationships exist. One example may be where a PAGS group has 2 parent groups that are also PAGS groups.

Caused by: java.lang.IllegalStateException: Multiple representations of the same entity [org.jasig.portal.groups.pags.dao.jpa.PersonAttributesGroupDefinitionImpl#28] are being merged. Detached: [org.jasig.portal.groups.pags.dao.jpa.PersonAttributesGroupDefinitionImpl@6a85fe0c[id=28,entityVersion=0,name=PAGS BYU Faculty,description=IDCard role Faculty,members=[],testGroups=[org.jasig.portal.groups.pags.dao.jpa.PersonAttributesGroupTestGroupDefinitionImpl@7ec3c751[id=22,entityVersion=0,group=org.jasig.portal.groups.pags.dao.jpa.PersonAttributesGroupDefinitionImpl@6a85fe0c,tests=[org.jasig.portal.groups.pags.dao.jpa.PersonAttributesGroupTestDefinitionImpl@6142b3c4[id=22,entityVersion=0,attributeName=idCardPrimaryRole,testerClass=org.jasig.portal.groups.pags.testers.StringEqualsTester,testValue=Affiliate,testGroup=org.jasig.portal.groups.pags.dao.jpa.PersonAttributesGroupTestGroupDefinitionImpl@7ec3c751]]]]]]; Detached: [org.jasig.portal.groups.pags.dao.jpa.PersonAttributesGroupDefinitionImpl@46bcb58a[id=28,entityVersion=0,name=PAGS BYU Faculty,description=IDCard role Faculty,members=[],testGroups=[org.jasig.portal.groups.pags.dao.jpa.PersonAttributesGroupTestGroupDefinitionImpl@4aa13dc0[id=22,entityVersion=0,group=org.jasig.portal.groups.pags.dao.jpa.PersonAttributesGroupDefinitionImpl@46bcb58a,tests=[org.jasig.portal.groups.pags.dao.jpa.PersonAttributesGroupTestDefinitionImpl@64b957f0[id=22,entityVersion=0,attributeName=idCardPrimaryRole,testerClass=org.jasig.portal.groups.pags.testers.StringEqualsTester,testValue=Affiliate,testGroup=org.jasig.portal.groups.pags.dao.jpa.PersonAttributesGroupTestGroupDefinitionImpl@4aa13dc0]]]]]]
at org.hibernate.event.internal.EntityCopyNotAllowedObserver.entityCopyDetected(EntityCopyNotAllowedObserver.java:51)
at org.hibernate.event.internal.MergeContext.put(MergeContext.java:262)
at org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:314)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:180)
at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:843)
at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:825)
at org.hibernate.engine.spi.CascadingAction$6.cascade(CascadingAction.java:288)
at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:396)
at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:339)
at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:207)
at org.hibernate.engine.internal.Cascade.cascadeCollectionElements(Cascade.java:426)
at org.hibernate.engine.internal.Cascade.cascadeCollection(Cascade.java:366)
at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:342)
at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:207)
at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:164)
at org.hibernate.event.internal.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:468)
at org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:337)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:180)
at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:843)
at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:825)
at org.hibernate.engine.spi.CascadingAction$6.cascade(CascadingAction.java:288)
at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:396)
at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:339)
at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:207)
at org.hibernate.engine.internal.Cascade.cascadeCollectionElements(Cascade.java:426)
at org.hibernate.engine.internal.Cascade.cascadeCollection(Cascade.java:366)
at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:342)
at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:207)
at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:164)
at org.hibernate.event.internal.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:468)
at org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:337)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:180)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:86)
at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:833)
at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:817)
at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:821)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:889)
at sun.reflect.GeneratedMethodAccessor110.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.jasig.portal.jpa.EventingLocalContainerEntityManagerFactoryBean$EventingEntityMangerInterceptor.invoke(EventingLocalContainerEntityManagerFactoryBean.java:134)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy213.merge(Unknown Source)
at sun.reflect.GeneratedMethodAccessor110.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:241)
at com.sun.proxy.$Proxy107.merge(Unknown Source)
at org.jasig.portal.groups.pags.dao.jpa.JpaPersonAttributesGroupDefinitionDao.updatePersonAttributesGroupDefinition(JpaPersonAttributesGroupDefinitionDao.java:98)
at sun.reflect.GeneratedMethodAccessor140.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:55)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy199.updatePersonAttributesGroupDefinition(Unknown Source)
at org.jasig.portal.io.xml.pags.PersonAttributesGroupImportHelper.addGroupMember(PersonAttributesGroupImportHelper.java:93)
at org.jasig.portal.io.xml.pags.PersonAttributesGroupImportHelper$addGroupMember$4.call(Unknown Source)
at Script24.run(Script24.groovy:2)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:345)
... 39 more

The problem seems to lie in how the PersonAttributesGroupImportHelper updates parent/child relationships – by passing a new collection to setMembers() instead of altering the existing collection. (PAGS groups and their relationships are JPA/Hibernate-managed objects.)

Environment

None

Assignee

Unassigned

Reporter

Andrew Wills

Labels

None

Estimated End Date

None

Components

Fix versions

Priority

Major
Configure