I am getting a ConcurrentModificationException when creating an EntityManagerFactory.
I have three objects Order, Event and Audits that should be persisted. I have created Order as an Entity. Events and Audits are Embeddedable/Components such that
1) An Order contains a list of events.
2) An Event contains a list of audits.
The application works when only events are embedded into order and audits are not mapped/used. When event class is modified to contain the list of audits the exception is thrown.
Is there a rule against having component class references from within another component?
Would really appreciate if someone can take a look and let me know what im missing.
I have removed the getters/setters from the code below for posting purposes. The class definitions for order, event and audits are
Code:
@Entity
@Table(name="MY_ORDER")
public class Order
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="order_id")
private long id;
@Column(name="qty", nullable=false)
private String quantity;
@Column(name="item_cd", nullable=false)
private String item_code;
@org.hibernate.annotations.CollectionOfElements
@JoinTable(
name = "ORDER_EVENTS",
joinColumns = @JoinColumn(name = "order_id")
)
@org.hibernate.annotations.IndexColumn(name="event_id", base = 1)
private List<Event> events;
}
Code:
@Embeddable
@Table(name="ORDER_EVENTS")
public class Event
{
@Column(name="event_desc", nullable=false)
private String description;
@org.hibernate.annotations.Parent
private Order order;
@org.hibernate.annotations.CollectionOfElements
@JoinTable(
name = "ORDER_AUDITS",
joinColumns = @JoinColumn(name = "event_id")
)
private List<Audit> audits;
}
Code:
@Embeddable
@Table(name="ORDER_AUDITS")
public class Audit
{
@org.hibernate.annotations.Parent
private Event event = null;
@Column(name="attrib", nullable=false)
private String field;
@Column(name="new_val", nullable=false)
private String oldValue;
@Column(name="new_val", nullable=false)
private String newValue;
}
Error thrown when executing
Code:
EntityManagerFactory factory = new HibernatePersistence().createEntityManagerFactory( getConfig() );
Stack Trace Code:
Exception in thread "main" 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:1128)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:316)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1112)
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.createEntityManagerFactory(Ejb3Configuration.java:706)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:137)
at com.fmrco.test.dao.BaseDAO.getEntityManager(BaseDAO.java:27)
at com.fmrco.test.dao.MyDAO.setEventsIntoOrder(MyDAO.java:33)
at com.fmrco.test.dao.MyDAO.main(MyDAO.java:27)
Hibernate version: Core version - 3.2.1GA and Annotations version - 3.3.1GA
Code:
Code: