Which version of EclipseLink are you using?
We had similar error long time ago but on a older branch.
The ConcurrentModificationException
come from IdentityHashMap, which is internal to EclipseLink, so I doubt client
code could be guilty.
The
only way I see client code been wrong is to have two threads using the same
entity manager.
We
have developed with Oracle an instrumented ArrayList, the same could be done
with IdentityHashMap, then when instrumented, the exception will also tell you
the stack that has modified the Map concurrently.
From:
eclipselink-users-bounces@xxxxxxxxxxx
[mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of Christopher.Mathrusse@xxxxxxxxxx
Sent: Wednesday, September 02, 2009 9:33 PM
To: EclipseLink User Discussions
Subject: [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...