I ran into something very similar. In my case I have parent/children unidirectional one-to-many relation.
class Parent
{
private ArrayList children;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name="parent_id", nullable = false)
@OrderBy(value = "time")
public List<Child> getChildred()
{
children.trimToSize();
return Collections.synchronizedList(children);
}
The test case that's failing is fairly standard:
Parent myParent = new Parent();
Child child1 = new Child();
Child child2 = new Child();
ArrayList<Child> children = new ArrayList<Child>();
children.add(child1);
children.add(child2);
myParent.setChildren(children);
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.merge(myParent);
em.flush();
em.getTransaction().commit();
em.close();
The stack trace is as follows:
java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(Unknown Source) at java.util.ArrayList$Itr.next(Unknown Source) at org.hibernate.engine.internal.Cascade.cascadeCollectionElements(Cascade.java:418) at org.hibernate.engine.internal.Cascade.cascadeCollection(Cascade.java:344) at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:307) at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:146) at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:95) at org.hibernate.event.internal.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:456) at org.hibernate.event.internal.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:239) at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:173) at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:69) at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:839) at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:821) at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:826) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:1161) --------------------------------- //here goes the code I posted above at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) 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.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
|