OpenJPA
  1. OpenJPA
  2. OPENJPA-398

ConcurrentModificationException at org.apache.openjpa.kernel.BrokerImpl

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Duplicate
    • Affects Version/s: 1.0.0, 1.0.1, 1.0.2, 1.1.0, 1.2.0
    • Fix Version/s: 2.1.0
    • Component/s: kernel
    • Labels:
      None
    • Environment:
      JDK Sun 1.6.0.06 on Ubuntu

      Description

      Hello.

      I'm trying to use OpenJPA in my project. I use Liferay based on Toncat as front-end.

      I use OpenJPA 1.0.0

      Today I have got strange exception -

      10:35:55,785 ERROR ConcurrentModificationException at java.util.HashMap$HashIterator.nextEntry(HashMap.java:787) at java.util.HashMap$KeyIterator.next(HashMap.java:823) at org.apache.openjpa.kernel.BrokerImpl$ManagedCache.dirtyCheck(BrokerImpl.java:4612)

      at org.apache.openjpa.kernel.BrokerImpl$ManagedCache.access$000(BrokerImpl.java:4352) at org.apache.openjpa.kernel.BrokerImpl.hasTransactionalObjects(BrokerImpl.java:3731)

      at org.apache.openjpa.kernel.BrokerImpl.setDirty(BrokerImpl.java:3848) at org.apache.openjpa.kernel.StateManagerImpl.setPCState(StateManagerImpl.java:207)

      at org.apache.openjpa.kernel.StateManagerImpl.dirty(StateManagerImpl.java:1532) at org.apache.openjpa.kernel.StateManagerImpl.dirty(StateManagerImpl.java:1471)

      at org.apache.openjpa.kernel.StateManagerImpl.dirtyCheck(StateManagerImpl.java:808) at org.apache.openjpa.kernel.BrokerImpl$ManagedCache.dirtyCheck(BrokerImpl.java:4612)

      at org.apache.openjpa.kernel.BrokerImpl$ManagedCache.access$000(BrokerImpl.java:4352) at org.apache.openjpa.kernel.BrokerImpl.hasTransactionalObjects(BrokerImpl.java:3731)

      at org.apache.openjpa.kernel.BrokerImpl.setDirty(BrokerImpl.java:3848) at org.apache.openjpa.kernel.StateManagerImpl.setPCState(StateManagerImpl.java:207)

      at org.apache.openjpa.kernel.StateManagerImpl.dirty(StateManagerImpl.java:1532) at org.apache.openjpa.kernel.StateManagerImpl.dirty(StateManagerImpl.java:1471)

      at org.apache.openjpa.kernel.StateManagerImpl.dirtyCheck(StateManagerImpl.java:808) at org.apache.openjpa.kernel.BrokerImpl$ManagedCache.dirtyCheck(BrokerImpl.java:4612)

      at org.apache.openjpa.kernel.BrokerImpl$ManagedCache.access$000(BrokerImpl.java:4352)

      It happens only, when I deploy application on portal, and only when service is first-time accessed.

      All tests work fine.

      Exception throws in get method
      Transactions are managed by Spring and i use Spring agent.

        Issue Links

          Activity

          Hide
          Pål GD added a comment -

          Do you have a reference in the class you're accessing to an object of the same class?
          This mail to the users list explains how to reproduce. This error also affects 1.1.0!

          http://mail-archives.apache.org/mod_mbox/openjpa-users/200806.mbox/%3C8F5D4C634753484685F8A5F5F38757002A483A9282@Mailserver1.tecwel.local%3E

          Show
          Pål GD added a comment - Do you have a reference in the class you're accessing to an object of the same class? This mail to the users list explains how to reproduce. This error also affects 1.1.0! http://mail-archives.apache.org/mod_mbox/openjpa-users/200806.mbox/%3C8F5D4C634753484685F8A5F5F38757002A483A9282@Mailserver1.tecwel.local%3E
          Hide
          Pål GD added a comment -

          Affects 1.0.2. and 1.1.0

          Show
          Pål GD added a comment - Affects 1.0.2. and 1.1.0
          Hide
          Heiko added a comment -

          Hi!

          I see exactly the same behaviour as described in this bug on 1.2.0.

          And yes, in my case, there is a reference to an object of the same class. It's a tree of objects. Each object has a @ManyToOne relationship to its parent and a @OneToMany relationship to its children. Parents and children are objects of the same class.
          This exception appears, when I try to add a child to the tree (add-operation on the java.util.List of children).

          The exception doesn't occur in the first or second level of the hierarchy, only on deeper levels.
          To test, wether concurrency is involved or not, I set openjpa.Multithreaded to true, but I got the same exception.
          Apart from that, I'm pretty sure, that there is only one thread.

          Using plain JPA in a Swing application (no Spring,...).

          I can make a short example, if it is of interest for you.

          Show
          Heiko added a comment - Hi! I see exactly the same behaviour as described in this bug on 1.2.0. And yes, in my case, there is a reference to an object of the same class. It's a tree of objects. Each object has a @ManyToOne relationship to its parent and a @OneToMany relationship to its children. Parents and children are objects of the same class. This exception appears, when I try to add a child to the tree (add-operation on the java.util.List of children). The exception doesn't occur in the first or second level of the hierarchy, only on deeper levels. To test, wether concurrency is involved or not, I set openjpa.Multithreaded to true, but I got the same exception. Apart from that, I'm pretty sure, that there is only one thread. Using plain JPA in a Swing application (no Spring,...). I can make a short example, if it is of interest for you.
          Hide
          Michael Dick added a comment -

          Hi Heiko, if you have a testcase available and can attach it to the issue that would help greatly.

          Show
          Michael Dick added a comment - Hi Heiko, if you have a testcase available and can attach it to the issue that would help greatly.
          Hide
          Mark Struberg added a comment -

          from what I've seen OPENJPA-641 may be the same problem.

          It contains a test case.

          Show
          Mark Struberg added a comment - from what I've seen OPENJPA-641 may be the same problem. It contains a test case.
          Hide
          Catalina Wei added a comment -

          Duplicate of OPENJPA-641, and the problem is not reproducible.

          Correction to testcase:

          Query q = em.createQuery("SELECT a FROM A a WHERE a.name=:cName")
          .setParameter(1, cName);
          should be:

          Query q = em.createQuery("SELECT a FROM A a WHERE a.name=:cName")
          .setParameter("cName", cName);

          /*

          • Licensed to the Apache Software Foundation (ASF) under one
          • or more contributor license agreements. See the NOTICE file
          • distributed with this work for additional information
          • regarding copyright ownership. The ASF licenses this file
          • to you under the Apache License, Version 2.0 (the
          • "License"); you may not use this file except in compliance
          • with the License. You may obtain a copy of the License at
            *
          • http://www.apache.org/licenses/LICENSE-2.0
            *
          • Unless required by applicable law or agreed to in writing,
          • software distributed under the License is distributed on an
          • "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
          • KIND, either express or implied. See the License for the
          • specific language governing permissions and limitations
          • under the License.
            */
            package org.apache.openjpa.persistence.kernel;

          import javax.persistence.EntityManager;
          import javax.persistence.Query;

          import org.apache.openjpa.persistence.kernel.common.apps.A;
          import org.apache.openjpa.persistence.test.SingleEMFTestCase;

          public class TestA641 extends SingleEMFTestCase {

          private int cId;
          private String cName = null;
          public void setUp() throws Exception

          { super.setUp(CLEAR_TABLES, A.class); 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(); cId = c.getId(); cName = c.getName(); em.close(); }

          public void testOpenjpa641()

          { EntityManager em = emf.createEntityManager(); //both methods of getting entity results in same error A c = em.find(A.class, cId); em.clear(); Query q = em.createQuery("SELECT a FROM A a WHERE a.name=:cName") .setParameter("cName", cName); A newC = (A)q.getSingleResult(); assertEquals(c.getName(), newC.getName()); em.close(); }

          }

          Show
          Catalina Wei added a comment - Duplicate of OPENJPA-641 , and the problem is not reproducible. Correction to testcase: Query q = em.createQuery("SELECT a FROM A a WHERE a.name=:cName") .setParameter(1, cName); should be: Query q = em.createQuery("SELECT a FROM A a WHERE a.name=:cName") .setParameter("cName", cName); /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package org.apache.openjpa.persistence.kernel; import javax.persistence.EntityManager; import javax.persistence.Query; import org.apache.openjpa.persistence.kernel.common.apps.A; import org.apache.openjpa.persistence.test.SingleEMFTestCase; public class TestA641 extends SingleEMFTestCase { private int cId; private String cName = null; public void setUp() throws Exception { super.setUp(CLEAR_TABLES, A.class); 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(); cId = c.getId(); cName = c.getName(); em.close(); } public void testOpenjpa641() { EntityManager em = emf.createEntityManager(); //both methods of getting entity results in same error A c = em.find(A.class, cId); em.clear(); Query q = em.createQuery("SELECT a FROM A a WHERE a.name=:cName") .setParameter("cName", cName); A newC = (A)q.getSingleResult(); assertEquals(c.getName(), newC.getName()); em.close(); } }
          Hide
          Michael Dick added a comment -

          Closing issue which has been resolved for some time. If you believe the issue is not resolved please reopen or open a new issue.

          Show
          Michael Dick added a comment - Closing issue which has been resolved for some time. If you believe the issue is not resolved please reopen or open a new issue.

            People

            • Assignee:
              Catalina Wei
              Reporter:
              Alexander
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development