gpt4 book ai didi

jpa - 无法在事务 : enlistResource returns 'false' 中登记连接

转载 作者:行者123 更新时间:2023-12-04 15:30:20 25 4
gpt4 key购买 nike

突然之间,对于选择查询,我不断收到以下错误。

Unable to enlist connection in transaction: enlistResource returns 'false'

这似乎是从 DBCP ( https://commons.apache.org/proper/commons-dbcp/jacoco/org.apache.commons.dbcp2.managed/TransactionContext.java.html ) 抛出的

本质上,这段代码调用 javax.transaction.Transaction.enlistResource

查看 API,它说“登记与目标事务对象关联的事务指定的资源。如果资源登记成功,则为 true;否则为 false。”

我仍然不清楚为什么抛出这个异常。
  • 什么是征用资源进行交易?
  • 当征募资源返回 false 时?我的意思是什么时候事务将无法征用资源?
  • 如何避免这个问题?

  • 技术栈:
  • TomEE 7.0.4
  • JPA
  • MariaDB

  • 数据源配置:

    <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]

    最佳答案

    刚刚遇到了同样的问题,并在我的日志文件中深入挖掘了一点。就在第一次出现之前

    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

    这一切让我找到了 old post来自 tomee-openejb 邮件列表。所以我最近的 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>

    手指交叉它会工作而没有任何进一步的问题。如果我不再在这里更新它就会正常工作。

    更多信息:
  • Tomee DataSource Configuration
  • 关于jpa - 无法在事务 : enlistResource returns 'false' 中登记连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48494276/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com