Andy McCall Andy McCall - 1 year ago 115
Java Question

Hibernate throwing a ConcurrentModificationException

I am writing some tests for a persistance layer I've been working on and I've ran into an exception that that I'm having trouble dealing with, a ConcurrentModificationException it's happening at

Which turns out to be this line of code:

final Map.Entry<String,UniqueKey> uniqueKeyEntry =;

After doing a little research I've found out that the exception is caused by one thread modifying this collection while this thread is iterating over it. That being said I feel like there's nothing that I'm doing that's causing this to happen any suggestions on troubleshooting?

BTW, Im using
hibernate 4.1.5
. Idk if that clears anything up or not. Here's my test:

public void testCreateMobsterUser() {
try {
final MobsterUserDAO test = new MobsterUserDAO(); //throws exception
//does stuff w/ return value...

As you can see we try and initialize the dao Let's see that code:

public MobsterUserDAO() {

Well that didn't show us much so let's look at the generic dao constructor and see if you see the problem there.

public MobsterBaseHibernateDAO(final Class<T> clazz) {
this.clazz = clazz;
//This next line is where the exception is actually occuring
final EntityManagerFactory factory = Persistence.createEntityManagerFactory("mobsterdb");
this.manager = (HibernateEntityManager) factory.createEntityManager();

Now I'm not sure what kind of rabbit hole Persistance.createEntityManagerFactory is, but that is the last line of my code that gets executed before the exception occurs.

Answer Source

Since it seems like a exception during internal housekeeping by Hibernate, I had assumed that its a bug. A quick search on Google does show a recently reported JIRA.

There is a resolution proposed but no idea when it will be released.

Hope this helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download