突然间,我为选择查询连续收到以下错误。
Unable to enlist connection in transaction: enlistResource returns 'false'
引发的
本质上,此代码调用javax.transaction.Transaction.enlistResource
查看API,它说“使用与目标Transaction对象关联的事务指定资源。如果资源成功登记,则为true;否则为false。”
我仍然不清楚为什么抛出这个异常。
Tech Stack:
数据源配置:
<Resource id="jdbc/myDS" type="javax.sql.DataSource">
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
</Resource>
堆栈追踪:
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.<init>(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]
答案 0 :(得分:3)
刚刚遇到同样的问题,并在我的日志文件中挖掘了一些。就在第一次出现之前
enlistResource returns 'false'
我找到了
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
进一步检查并找到了
WARNING [https-jsse-nio-8443-exec-1] org.apache.geronimo.transaction.manager.TransactionImpl.enlistResource Unable to enlist XAResource org.apache.openejb.resource.jdbc.managed.local.LocalXAResource@2ce72e5a, errorCode: 0
javax.transaction.xa.XAException: Count not turn off auto commit for a XA transaction
这一切都让我从tomee-openejb邮件列表中找到old post。所以我最近的tomee.xml
配置看起来像这样:
<Resource id="[Resourcename]" type="javax.sql.DataSource">
jdbcDriver = com.mysql.jdbc.Driver
jdbcUrl = jdbc:mysql://localhost:3306/[Databasename]
userName = [Username]
password = [Password]
</Resource>
现在我将其更改为以下配置:
<Resource id=[Name] type="javax.sql.DataSource">
jdbcDriver = com.mysql.jdbc.Driver
jdbcUrl = jdbc:mysql://localhost:3306/[Databasename]
jtaManaged = true
username = [Username]
password = [Password]
defaultAutoCommit = false
testOnReturn = true
testWhileIdle = true
timeBetweenEvictionRunsMillis = 60
initialSize = 2
minIdle = 2
validationQuery = "select 1"
</Resource>
手指交叉,它将无任何进一步的问题。如果我不再在这里更新它将会正常工作。
更多信息: