title: Aren't multiple transactions supposed to concur with em.getTransaction()?
body: <p>When I execute:</p>
  
  
  
  <pre class="lang-java prettyprint-override"><code>public void beginTransaction() {
      em.getTransaction().begin();
  }
  </code></pre>
  
  <p>following an active transaction started in the same way, I get the following exception:</p>
  
  <pre class="lang-java prettyprint-override"><code>Exception Description: Transaction is currently active
  java.lang.IllegalStateException: 
  Exception Description: Transaction is currently active
          at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.begin(EntityTransactionImpl.java:45)
          at com.mysimpatico.memoplatform.persistence.Database.beginTransaction(Database.java:44)
          at com.mysimpatico.memoplatform.persistence.tests.PersistenceTest.setUp(PersistenceTest.java:39)
  </code></pre>
  
  <p>The underlying DBMS is embedded apache derby which to my knowledge doesn't support multiple connections from different JVMS, but otherwise supports concurrent transactions.<a href="http://db.apache.org/derby/papers/DerbyTut/embedded_intro.html" rel="nofollow">Documentation</a></p>
  
  <p>This test code fails:</p>
  
  <pre class="lang-java prettyprint-override"><code>public &lt;Entity&gt; int getNo(final Class&lt;Entity&gt; entityClass) {
      final CriteriaBuilder qb = em.getCriteriaBuilder();
      final CriteriaQuery&lt;Long&gt; cq = qb.createQuery(Long.class);
      cq.select(qb.count(cq.from(entityClass)));
      final int ret = em.createQuery(cq).getSingleResult().intValue();
      return ret;
  }
  
  protected void insertWords(final List&lt;String[]&gt; expressionDefTriples, MUser usr, final MeaningsDatabase mengsDB) throws Exception {
      for (String[] expressionDefTriple : expressionDefTriples) {
          mengsDB.persistSynonyms(MeaningsDatabase.toEnumMap(expressionDefTriple, usr));
          testSynonymsPersistance(expressionDefTriple,mengsDB);
      }
  }
  
  protected void testSynonymsPersistance(final String[] expDefTriple, final MeaningsDatabase mengsDB) {
      final Expression exp = mengsDB.get(Expression.class, expDefTriple[0]);
      testGender(exp, expDefTriple[2]);
      final Expression def = mengsDB.get(Expression.class, expDefTriple[1]);
      assertNotNull(def);
      assertTrue(exp.getMengs().size() &gt; 0);
      assertTrue(def.getMengs().size() &gt; 0);
      assertTrue(mengsDB.getNo(Meaning.class) &gt; 0); //fails here
  }
  
  public void persistSynonyms(final EnumMap&lt;Input, MemoEntity&gt; input) throws MultipleMengsException {
      final Expression def = extractExp(input, Input.definition);
      final Expression exp = extractExp(input, Input.expression);
      final MUser usr = extractUsr(input);
  
      beginTransaction();
      final Meaning meng = persistMeng(exp, usr, def);
      commitTransaction();
      signalContentAvailability();
      logInsertion(meng, exp, def);
  }
  </code></pre>
  
  <p>Essentially I start and commit a transaction within the same em, but then when I come to execute the getNo() method using the same em, it doesn't find what has been committed by the previous. I don't see where's the problem. There's clearly an issue since 'local' code like em.find(..) finds the committed changes, but not the criteria query.</p>