I have the same issue. Also I find HHH-7605 defect (https://hibernate.onjira.com/browse/HHH-7605), but looks like that defect was not submitted correctly and no one want to fix them.
My debug log:
Code:
00:44:16,642 DEBUG ActionQueue:202 - Executing identity-insert immediately
00:44:16,642 DEBUG SqlStatementLogger:104 - insert into PRODUCT_SIZE_PRICE (PRICE, PRODUCT_ID, SIZE) values (?, ?, ?)
00:44:16,642 DEBUG PreparedStatementHandle:197 - insert into PRODUCT_SIZE_PRICE (PRICE, PRODUCT_ID, SIZE) values ('4613', 45861, '19.0мм 1.57гр')
00:44:16,643 DEBUG IdentifierGeneratorHelper:93 - Natively generated identity: 212748
00:44:16,643 DEBUG UpdateTimestampsCache:78 - Pre-invalidating space [PRODUCT_SIZE_PRICE], timestamp: 5575941802569728
00:44:16,643 DEBUG EhcacheGeneralDataRegion:100 - key: PRODUCT_SIZE_PRICE value: 5575941802569728
00:44:16,643 ERROR GenericDaoHibernate:80 - An entity copy was already assigned to a different entity.
java.lang.IllegalStateException: An entity copy was already assigned to a different entity.
at org.hibernate.event.internal.EventCache.put(EventCache.java:184)
at org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:285)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:151)
at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:910)
at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:892)
at org.hibernate.engine.spi.CascadingAction$6.cascade(CascadingAction.java:288)
at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:380)
at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:323)
at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:208)
at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:165)
at org.hibernate.event.internal.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:439)
at org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:308)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:151)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:76)
at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:900)
at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:884)
at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:888)
at com.navigator.db.dao.impl.GenericDaoHibernate.saveOrUpdate(GenericDaoHibernate.java:78)
at sun.reflect.GeneratedMethodAccessor52.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
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.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.navigator.timer.GoldAffiliateCsvParser.parseAndSaveProductFromKupiZolotoLine(GoldAffiliateCsvParser.java:354)
at com.navigator.timer.GoldAffiliateCsvParser.run(GoldAffiliateCsvParser.java:113)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I would to clarify that use "orphanRemoval=true" for this collection. And this error occurred only first time (during object creating - id is null at this place). When I updating existing object with same collection all works fine. Looks like that this is wrong hash/equals methods (or Ehcache bug???), but why this worked fine in 3.6? Any opinion?
--------------------------------------------------------------------------------------------------------------------------------------------------
After
6 days trying to fix this issue downgraded to 4.1.0.Final and looks like all works fine now.