| I feel like I am getting something similar (Wildfly 14 which utilizes Hibernate 5.3.6.Final), though I am unable to create a simple test case to reproduce it. A snippet of the stack trace I see...
Caused by: java.util.ConcurrentModificationException
at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:966)
at java.util.LinkedList$ListItr.next(LinkedList.java:888)
My Maven Configuration (From http://docs.jboss.org/hibernate/orm/5.3/userguide/html_single/Hibernate_User_Guide.html#BytecodeEnhancement-enhancement)
<plugin>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>5.3.6.Final</version>
<executions>
<execution>
<goals>
<goal>enhance</goal>
</goals>
<configuration>
<failOnError>true</failOnError>
<enableLazyInitialization>true</enableLazyInitialization>
<enableDirtyTracking>true</enableDirtyTracking>
<enableAssociationManagement>true</enableAssociationManagement>
</configuration>
</execution>
</executions>
</plugin>
My current test class similar to above which I am working on to try and reproduce with. Any tips?
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.transaction.UserTransaction;
import org.jboss.arquillian.junit.Arquillian;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(Arquillian.class)
public class HibernateMavenBytecodeEnhancedAssociationTest {
@Inject
private EntityManager em;
@Inject
private UserTransaction utx;
@Test
public void testAssociation() throws Exception {
Long parentId;
{
utx.begin();
em.joinTransaction();
Parent parent = new Parent();
em.persist(parent);
parentId = parent.getId();
List<Child> children = new ArrayList<>();
for (long i = 0; i < 10; i++) {
Child child = new Child(parent);
children.add(child);
}
parent.setChildren(children);
utx.commit();
}
{
utx.begin();
em.joinTransaction();
Parent parent = em.find(Parent.class, parentId);
List<Child> newChildren = new ArrayList<>();
for (long i = 0; i < 10; i++) {
Child child = new Child(parent);
newChildren.add(child);
}
parent.setChildren(newChildren);
utx.commit();
}
}
@Entity
public static class Parent {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<Child> children = new ArrayList<>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public List<Child> getChildren() {
return children;
}
public void setChildren(List<Child> children) {
this.children = children;
}
public void addChild(Child child) {
children.add(child);
}
@Override
public String toString() {
return "Parent{" +
"id=" + id +
'}';
}
}
@Entity
public static class Child {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "parent_id")
private Parent parent;
public Child() {
}
public Child(Parent parent) {
this.parent = parent;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Parent getParent() {
return parent;
}
public void setParent(Parent parent) {
this.parent = parent;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Child child = (Child) o;
if (id != null ? !id.equals(child.id) : child.id != null) return false;
return parent != null ? parent.equals(child.parent) : child.parent == null;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (parent != null ? parent.hashCode() : 0);
return result;
}
}
}
|