gpt4 book ai didi

java - Hibernate - Bitronix - Spring - 无法征用多个非 XA 资源

转载 作者:太空宇宙 更新时间:2023-11-04 15:10:48 25 4
gpt4 key购买 nike

我最近更新到 Hibernate 4.2.8.Final 并尝试了 4.3.1.Final 但是,在使用 时我开始遇到以下异常使用 spring 框架 3.1 在事务上下文中查找 方法。我正在使用 Bitronix 交易管理器 2.4.3。我不确定我是否以正确的方式使用hibernate,但正如我所描述的,这个问题是在hibernate版本更新后才开始出现的。

Caused by: org.hibernate.exception.GenericJDBCException: could not prepare statement
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:196)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:160)
at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.prepareQueryStatement(AbstractLoadPlanBasedLoader.java:257)
at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeQueryStatement(AbstractLoadPlanBasedLoader.java:201)
at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:137)
at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:102)
at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:186)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4120)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:502)
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:467)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:212)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:274)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:150)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1066)
at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:176)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2533)
at org.hibernate.internal.SessionImpl.get(SessionImpl.java:1019)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1104)
... 76 more
Caused by: java.sql.SQLException: error enlisting a JdbcConnectionHandle of a JdbcPooledConnection from datasource defaultDataSource in state ACCESSIBLE with usage count 1 wrapping a JDBC LrcXAConnection on com.mysql.jdbc.JDBC4Connection@11d1bb73 on a JDBC LrcConnectionHandle on a JDBC LrcXAResource in state NO_TX
at bitronix.tm.resource.jdbc.JdbcConnectionHandle.enlistResource(JdbcConnectionHandle.java:87)
at bitronix.tm.resource.jdbc.JdbcConnectionHandle.prepareStatement(JdbcConnectionHandle.java:242)
at sun.reflect.GeneratedMethodAccessor43.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at bitronix.tm.resource.jdbc.BaseProxyHandlerClass.invoke(BaseProxyHandlerClass.java:64)
at com.sun.proxy.$Proxy23.prepareStatement(Unknown Source)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:162)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:186)
... 93 more
Caused by: bitronix.tm.internal.BitronixSystemException: cannot enlist more than one non-XA resource, tried enlisting an XAResourceHolderState with uniqueName=defaultDataSource XAResource=a JDBC LrcXAResource in state NO_TX with XID null, already enlisted: an XAResourceHolderState with uniqueName=defaultDataSource XAResource=a JDBC LrcXAResource in state STARTED (started) with XID a Bitronix XID [737072696E672D62746D0000000023E25108000007C6 : 737072696E672D62746D0000000023E2510F000007CC]
at bitronix.tm.internal.XAResourceManager.enlist(XAResourceManager.java:107)
at bitronix.tm.BitronixTransaction.enlistResource(BitronixTransaction.java:130)
at bitronix.tm.resource.common.TransactionContextHelper.enlistInCurrentTransaction(TransactionContextHelper.java:69)
at bitronix.tm.resource.jdbc.JdbcConnectionHandle.enlistResource(JdbcConnectionHandle.java:85)
... 101 more

persistence.xml配置:

<persistence-unit name="default" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>default</jta-data-source>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
</persistence-unit>

Spring dataSource 和 bitronix 配置:

<bean id="defaultDataSource" class="bitronix.tm.resource.jdbc.PoolingDataSource"
depends-on="transactionManager" init-method="init" destroy-method="close">
<property name="className" value="bitronix.tm.resource.jdbc.lrc.LrcXADataSource" />
<property name="uniqueName" value="defaultDataSource" />
<property name="minPoolSize" value="${ds.default.minPoolSize}" />
<property name="maxPoolSize" value="${ds.default.maxPoolSize}" />
<property name="maxIdleTime" value="${ds.default.maxIdleTime}" />
<property name="useTmJoin" value="true" />
<property name="deferConnectionRelease" value="true" />
<property name="automaticEnlistingEnabled" value="true" />
<property name="allowLocalTransactions" value="true" />
<property name="isolationLevel" value="READ_COMMITTED" />
<property name="shareTransactionConnections" value="false"/>
<property name="driverProperties">
<props>
<prop key="driverClassName">${ds.default.driverClass}</prop>
<prop key="url">${ds.default.url}</prop>
<prop key="user">${ds.default.user}</prop>
<prop key="password">${ds.default.password.encrypted}</prop>
</props>
</property>
</bean>

<bean id="bitronixConfig" factory-method="getConfiguration" class="bitronix.tm.TransactionManagerServices">
<property name="serverId" value="spring-btm" />
<property name="logPart1Filename" value="${catalina.base}/logs/tlog/btm1.tlog" />
<property name="logPart2Filename" value="${catalina.base}/logs/tlog/btm2.tlog" />
<property name="defaultTransactionTimeout" value="600" />
<property name="warnAboutZeroResourceTransaction" value="false" />
<property name="journal" value="null" />
</bean>

<bean id="bitronixTransactionManager" class="bitronix.tm.TransactionManagerServices"
factory-method="getTransactionManager" destroy-method="shutdown" depends-on="bitronixConfig" />

最佳答案

提供程序类从 org.hibernate.ejb.HibernatePersistence 更改为至org.hibernate.jpa.HibernatePersistenceProvider在新版本的 Hibernate 中检查这是否能解决您的问题。

关于java - Hibernate - Bitronix - Spring - 无法征用多个非 XA 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21351049/

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