Skip to main content

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

I'm using EclipseLink 1.1.2 (just upgraded from 1.1.1 which I also had the
same issue with)

I have an OrderProcess entity that contains a list of Addresses. It is a one
sided 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;
....
}

I'm attempting to update the address list on the OrderProcess. I don't want
to retain any relationships that currently exist. So I'm attempting to
simply replace the existing Address list with a new one. Something like the
following.

  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)) {
      orderAddresses.add(address);
    }
  }

  
  // assign the addresses to the process
  process.setAddresses(orderAddresses);

  process.setModDate(Calendar.getUTCInstance());
  Process updated = em.merge(process);        
  em.flush();

The above code executes successfully except when there are existing
Addresses associated to the OrderProcess. When the call to flush() gets
executed I get the following exception:

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)

If I delete the associated Addresses from the ORDER_PROCESS_ADDRESS table
and reprocess the OrderProcess then everything functions as expected without
any Exception. 

So it seems to me that I am incorrectly assigning the Addresses. Do I need
to remove them prior to the assignment? Or is there another way that I need
to perform the assignment?

Thanks for the help..
-- 
View this message in context: http://www.nabble.com/ConcurrentModificationException-tp25282265p25282265.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top