title: Unable to enlist connection in transaction: enlistResource returns 'false'
body: <p>All of sudden I got the following error continuously for a select query.</p>
  
  <pre class="lang-none prettyprint-override"><code>Unable to enlist connection in transaction: enlistResource returns 'false'
  </code></pre>
  
  <p>This appears to be thrown from DBCP (<a href="https://commons.apache.org/proper/commons-dbcp/jacoco/org.apache.commons.dbcp2.managed/TransactionContext.java.html" rel="nofollow noreferrer">https://commons.apache.org/proper/commons-dbcp/jacoco/org.apache.commons.dbcp2.managed/TransactionContext.java.html</a>)</p>
  
  <p>Essentially, this code calls javax.transaction.Transaction.enlistResource</p>
  
  <p>Looking at the API, it says "Enlist the resource specified with the transaction associated with the target Transaction object. true if the resource was enlisted successfully; otherwise false."</p>
  
  <p>I am still not clear why this exception thrown.</p>
  
  <ol>
  <li>What is enlist the resource to transaction?</li>
  <li>When enlist resource returns false? I mean when transaction will not be able to enlist the resource?</li>
  <li>How to avoid this problem?</li>
  </ol>
  
  <p>Tech Stack:</p>
  
  <ul>
  <li>TomEE 7.0.4</li>
  <li>JPA</li>
  <li>MariaDB</li>
  </ul>
  
  <p>Data source config:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Resource id="jdbc/myDS" type="javax.sql.DataSource"&gt;
      dataSourceCreator = tomcat
      jtaManaged        = true
      driverClassName   = ${jdbc.driver}
      url               = ${jdbc.url}
      username          = ${jdbc.username}
      password          = ${jdbc.password}
      initialSize       = 5
      maxActive         = 100
      maxIdle           = 10
      minIdle           = 5
      maxWait           = 30000
      validationQuery   = SELECT 1
      testOnBorrow      = false
      testOnReturn      = false
      testWhileIdle     = true
      timeBetweenEvictionRunsMillis = 1800000
      numTestsPerEvictionRun = 2
      minEvictableIdleTimeMillis = 1800000
      accessToUnderlyingConnectionAllowed = false
  &lt;/Resource&gt;
  </code></pre>
  
  <p>Stack Trace:</p>
  
  <pre class="lang-none prettyprint-override"><code>Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: Unable to enlist connection in transaction: enlistResource returns 'false'. 
      at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:218) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:198) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$000(LoggingConnectionDecorator.java:58) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection.prepareStatement(LoggingConnectionDecorator.java:250) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:133) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.lib.jdbc.ConfiguringConnectionDecorator$ConfiguringConnection.prepareStatement(ConfiguringConnectionDecorator.java:139) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:133) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$RefCountConnection.prepareStatement(JDBCStoreManager.java:1642) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:122) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:513) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:493) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.jdbc.sql.SelectImpl.prepareStatement(SelectImpl.java:480) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.jdbc.sql.SelectImpl.execute(SelectImpl.java:421) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.jdbc.sql.SelectImpl.execute(SelectImpl.java:392) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.jdbc.sql.LogicalUnion$UnionSelect.execute(LogicalUnion.java:427) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.jdbc.sql.LogicalUnion.execute(LogicalUnion.java:230) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.jdbc.sql.LogicalUnion.execute(LogicalUnion.java:220) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.jdbc.kernel.SelectResultObjectProvider.open(SelectResultObjectProvider.java:93) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.kernel.QueryImpl$PackingResultObjectProvider.open(QueryImpl.java:2075) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.lib.rop.EagerResultList.&lt;init&gt;(EagerResultList.java:33) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1257) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1013) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:869) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:800) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:541) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:274) ~[openjpa-2.4.2.jar:2.4.2]
      at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:290) ~[openjpa-2.4.2.jar:2.4.2]
  </code></pre>