Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] ConcurrentModificationException


I'm having a bit of trouble with a parent-child relationship.

public class OrderProcess {
  @OneToMany
  @JoinTable(
      name = "ORDER_PROCESS_ADDRESS",
      joinColumns = @JoinColumn(name = "ORDER_PROCESS_ID"),
      inverseJoinColumns = @JoinColumn(name = "ADDRESS_ID"))  
  private List<Address> addresses;

...
}

Address has no reference to the OrderProcess.

I have the small bit of code below:


java.util.List<Address> orderAddresses = new java.util.ArrayList<Address>();

for(Address address : externalAddresses) {
  // Get a reference to the entity
  address = addressFacade.findExisting(address.getExternalId(), address.getNameType(), address.getOrganization(), process.getSourceRecordDate());
  if(!orderAddresses.contains(address)) {
        // associate it.
        orderAddresses.add(address);
  }
}
                               
// assign the addresses to the process
process.setAddresses(orderAddresses);

Process updated = em.merge(process);


The above works well without any issues unless the OrderProcess contains addresses prior to entering this code, and once the transaction attempts to commit I get a ConcurrentModificationException thrown from EclipseLink.

javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean; nested exception is: java.util.ConcurrentModificationException
java.util.ConcurrentModificationException
  at java.util.IdentityHashMap$IdentityHashMapIterator.nextIndex(IdentityHashMap.java:715)
  at java.util.IdentityHashMap$KeyIterator.next(IdentityHashMap.java:804)
  at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.calculateChanges(UnitOfWorkImpl.java:567)
  at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.writeChanges(RepeatableWriteUnitOfWork.java:308)
  at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:527)
  at com.sun.enterprise.util.EntityManagerWrapper.flush(EntityManagerWrapper.java:331)


I know this must be something to do with the way that I am performing the assignment of the addresses. So what am I overlooking or doing incorrectly?

Thanks for the help...

Back to the top