-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Hibernate threw "ConcurrentModificationException"
PostPosted: Thu Sep 06, 2007 5:39 pm 
Newbie

Joined: Thu Jul 26, 2007 2:28 pm
Posts: 9
I was using the Hibernate Entity Manager. I built a network model of objects from the annotated classes as well as the non-annotated classes. When I was done with the internal data object creation, I tried to save objects to the MySQL database. The first time I called a method in the Persistent class, Hibernate threw the "ConcurrentModificationException:"

entityManagerFactory = Persistence.createEntityManagerFactory("manager");

The line above caused the exception. I don't understand why. Does that mean that Hibernate had already created the entity manager factory before I invoked the createEntityManagerFactory method? How can I resolve this exception?



Hibernate versions:

hibernate-3.2
hibernate-annotations-3.3.0.GA
hibernate-entitymanager-3.3.1.GA

I am using the Entity Manager which includes all the above core libraries.

Full stack trace of any exception that occurs:

Exception in thread "main" javax.persistence.PersistenceException: java.util.ConcurrentModificationException
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:258)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at com.cra.trek2.model.database.DataEntityManager.<init>(DataEntityManager.java:29)
at com.cra.trek2.model.base.ConceptMapFactory.createConceptMap(ConceptMapFactory.java:43)
at com.cra.trek2.demo.DemoRunner.testCxlImport(DemoRunner.java:225)
at com.cra.trek2.demo.DemoRunner.main(DemoRunner.java:51)
Caused by: java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
at java.util.AbstractList$Itr.remove(Unknown Source)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1131)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:316)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1269)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:150)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:888)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:186)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:246)
... 7 more


Name and version of the database you are using:

mysql-connector-java-3.1.13-bin.jar


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 06, 2007 6:22 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
probably yes. If you use JPA outside an container you are responsible to configure the manager only once. This is the same as with a Hibernate SessionFactory.

You might put the configuration inside a static block to guaranty this.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 07, 2007 5:55 pm 
Newbie

Joined: Thu Jul 26, 2007 2:28 pm
Posts: 9
Following the advice from Sebastian, I tried to set up a static initialization in my main class, but Hibernate still threw the ConcurrentModificationException.

I am not sure if Hibernate could not handle complex convoluted relationships among the entities. For example, class A has a 1-to-Many relationship with class B through a HashMap attribute. Class B has an abstract super class S that has a 1-To-Many relationship to class C. Class C in turn has a Many-to-1 relationship with Class S twice because of the presence of two distinct attributes of the same type. I used JOINED as the inheritance strategy (i.e., table per subclass) for entity classes as well as some value type components.

Here is the new exception trace:

java.lang.ExceptionInInitializerError
Caused by: javax.persistence.PersistenceException: java.util.ConcurrentModificationException
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:258)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at com.cra.trek2.model.database.DataEntityManager.<init>(DataEntityManager.java:29)
at com.cra.trek2.demo.DemoRunner.<clinit>(DemoRunner.java:37)
Caused by: java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
at java.util.AbstractList$Itr.remove(Unknown Source)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1131)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:316)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1269)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:150)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:888)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:186)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:246)
... 5 more
Exception in thread "main"


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 10, 2007 1:49 pm 
Newbie

Joined: Thu Jul 26, 2007 2:28 pm
Posts: 9
Hibernate seemed to have problem mapping a collection of values in one of my classes causing the ConcurrentModificationException. For the sake of discussion, let's have the following classes:

Code:
@Entity
class A {
  @Id @GeneratedValue
  @Column(updatable = false, insertable = false)
  private Long id;

  @org.hibernate.annotations.CollectionOfElements
  @JoinTable(name = "A_B",  joinColumns =   @JoinColumn(name = "id"))
  @org.hibernate.annotations.MapKey(columns = @Column(name = "MapKey"))
  private Map<String, B> m;
}

@Embeddable
class B {
  @org.hibernate.annotations.CollectionOfElements
  @Column(nullable = false)
  private Set<C> set = new HashSet<C>();
}

@Embeddable
class C {
  @Column(nullable = false)
  String f1;

  @Column(nullable = false)
  String f2;
}


I still don't understand why Hibernate always threw the ConcurrentModificationException whenever I uncommented the field "m" in class A. Could someone in the Hibernate team provide some insights here?

Regards,
William


Top
 Profile  
 
 Post subject: Hibernate threw "ConcurrentModificationException"
PostPosted: Tue Sep 11, 2007 4:51 am 
Newbie

Joined: Tue Sep 04, 2007 2:53 am
Posts: 7
I am facing a similar problem - http://forum.hibernate.org/viewtopic.php?t=979164&highlight=.

I have not come across any documentation that suggests of any existing limitation for doing the above. So i am assuming this could be an issue in hibernate. Can anyone confirm ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.