openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Catalina Wei (JIRA)" <j...@apache.org>
Subject [jira] Closed: (OPENJPA-641) ConcurrentModificationException with self-referring entity-class when not running the enhancer
Date Thu, 19 Aug 2010 22:55:18 GMT

     [ https://issues.apache.org/jira/browse/OPENJPA-641?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Catalina Wei closed OPENJPA-641.
--------------------------------

         Assignee: Catalina Wei
    Fix Version/s: 2.1.0
       Resolution: Cannot Reproduce

Problem is not reproducible

> ConcurrentModificationException with self-referring entity-class when not running the
enhancer
> ----------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-641
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-641
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: build / infrastructure, datacache, jpa
>    Affects Versions: 1.0.2, 1.1.0
>         Environment: Happens when not running the enhancer. Note that the problem also
occurs when the Multithreaded property is set.
>            Reporter: Pål GD
>            Assignee: Catalina Wei
>             Fix For: 2.1.0
>
>
> 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:
> @Entity
> public class A {
>         @Id
>         @GeneratedValue(strategy = GenerationType.IDENTITY)
>         private int id;
>         private String name;
>         @ManyToOne
>         @Column(name = "parent")
>         private A parent;
>         public A() {
>                 name = "";
>         }
>         public A(String name) {
>                 this.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 a.name=:cName")
>                                 .setParameter(1, cName);
>                 A newC = (A)q.getSingleResult();
>                 em.getTransaction().commit();
>                 em.close();
>                 System.out.println(newC);
>                 emf.close();
>         }
>         //getters and setters
> }
> persistence.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     version="1.0">
>     <persistence-unit name="system" transaction-type="RESOURCE_LOCAL">
>                 <class>no.tecwel.A</class>
>        <properties>
>                 <!-- 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"/>
>         </properties>
>     </persistence-unit>
> </persistence>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message