title: Hibernate throwing a ConcurrentModificationException
body: <p>I am writing some tests for a <em>persistance layer</em> I've been working on and I've ran into an exception that that I'm having trouble dealing with, a <em>ConcurrentModificationException</em> it's happening at <em><code>org.hibernate.mapping.Table.cleanseUniqueKeyMap(Table.java:291)</code></em>. <br/>Which turns out to be this line of code:</p>
  
  <pre><code>final Map.Entry&lt;String,UniqueKey&gt; uniqueKeyEntry = uniqueKeyEntries.next();
  </code></pre>
  
  <p>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?</p>
  
  <p>BTW, Im using <code>hibernate 4.1.5</code>. Idk if that clears anything up or not. Here's my test:</p>
  
  <pre><code>@Test
  public void testCreateMobsterUser() {
     try {            
         final MobsterUserDAO test = new MobsterUserDAO(); //throws exception
         //does stuff w/ return value...
  </code></pre>
  
  <p>As you can see we try and initialize the dao Let's see that code:</p>
  
  <pre><code>public MobsterUserDAO() {
      super(MobsterUser.class);
  }
  </code></pre>
  
  <p>Well that didn't show us much so let's look at the generic dao constructor and see if you see the problem there.</p>
  
  <pre><code>public MobsterBaseHibernateDAO(final Class&lt;T&gt; 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();
  }
  </code></pre>
  
  <p>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.</p>