1. OpenJPA
  2. OPENJPA-641

ConcurrentModificationException with self-referring entity-class when not running the enhancer


    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.0.2, 1.1.0
    • Fix Version/s: 2.1.0
    • Labels:
    • Environment:
      Happens when not running the enhancer. Note that the problem also occurs when the Multithreaded property is set.


      Sometimes while fetching an instance of an entity-class with a self-reference (ManyToOne, for creating a hierarchy), I get a ConcurrentModificationException. This only seems to happen when the enhancer hasn't been loaded. Also it seems there has to be multiple levels in the hierarchy for this to occur.

      I have created an example which reproduces the Exception.

      The code:

      public class A {
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private int id;

      private String name;

      @Column(name = "parent")
      private A parent;

      public A()

      { name = ""; }

      public A(String name)

      { = name; }

      public static void main(String[] args)

      { EntityManagerFactory emf = Persistence .createEntityManagerFactory("system"); EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); // a A a = new A("a"); em.persist(a); // b A b = new A("b"); b.setParent(a); em.persist(b); // c A c = new A("c"); c.setParent(b); em.persist(c); em.getTransaction().commit(); em.close(); // getting c's data int cId = c.getId(); String cName = c.getName(); em = emf.createEntityManager(); em.getTransaction().begin(); //both methods of getting entity results in same error // A newC = em.find(A.class, cId); Query q = em.createQuery("SELECT a FROM A a WHERE") .setParameter(1, cName); A newC = (A)q.getSingleResult(); em.getTransaction().commit(); em.close(); System.out.println(newC); emf.close(); }

      //getters and setters



      <?xml version="1.0" encoding="UTF-8"?>
      <persistence xmlns=""

      <persistence-unit name="system" transaction-type="RESOURCE_LOCAL">
      <!-- this has no effect
      <property name="openjpa.Multithreaded" value="true"/> -->

      <property name="openjpa.ConnectionURL" value="jdbc:mysql://db.home.local/system "/>
      <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
      <property name="openjpa.ConnectionUserName" value="username"/>
      <property name="openjpa.ConnectionPassword" value="password"/>
      <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(SchemaAction='add,deleteTableContents',ForeignKeys='true')"/>
      <property name="openjpa.Log" value="DefaultLevel=TRACE"/>

        Issue Links


          Pål GD created issue -
          Mark Struberg made changes -
          Field Original Value New Value
          Link This issue is related to OPENJPA-398 [ OPENJPA-398 ]
          Catalina Wei made changes -
          Status Open [ 1 ] Closed [ 6 ]
          Assignee Catalina Wei [ fancy ]
          Fix Version/s 2.1.0 [ 12314542 ]
          Resolution Cannot Reproduce [ 5 ]


            • Assignee:
              Catalina Wei
              Pål GD
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: