更新到 Hibernate 5 后无法访问 TransactionManager 或 UserTransaction [英] Unable to access TransactionManager or UserTransaction after updating to Hibernate 5

查看:52
本文介绍了更新到 Hibernate 5 后无法访问 TransactionManager 或 UserTransaction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从 Hibernate 4.2.19 更新到 Hibernate 5.1.2.当然,很少有人说事情没有按计划进行.在解决了几个问题(其中 JOIN FETCH 必须由 JOIN 代替)后,我现在遇到了下一个问题:

I just updated from Hibernate 4.2.19 to Hibernate 5.1.2. Of course, little it is to say that things are not going as planned. After solving several issues (among which JOIN FETCH had to be replaced by JOIN), I now run into the next issue:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'idolConfig': Invocation of init method failed; nested exception is org.hibernate.resource.transaction.backend.jta.internal.JtaPlatformInaccessibleException: Unable to access TransactionManager or UserTransaction to make physical transaction delegate
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1575)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    [...]
Caused by: org.hibernate.resource.transaction.backend.jta.internal.JtaPlatformInaccessibleException: Unable to access TransactionManager or UserTransaction to make physical transaction delegate
    at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.makePhysicalTransactionDelegate(JtaTransactionCoordinatorImpl.java:229)
    at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.getTransactionDriverControl(JtaTransactionCoordinatorImpl.java:203)
    at org.hibernate.engine.transaction.internal.TransactionImpl.<init>(TransactionImpl.java:36)
    at org.hibernate.internal.AbstractSessionImpl.getTransaction(AbstractSessionImpl.java:313)
    at org.hibernate.internal.SessionImpl.<init>(SessionImpl.java:281)
    at org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl.openSession(SessionFactoryImpl.java:1326)
    at org.hibernate.jpa.internal.EntityManagerImpl.internalGetSession(EntityManagerImpl.java:133)
    [...]

日志显示无法加载 JtaPlatform:

The logs show that the JtaPlatform could not be loaded:

2016-11-14 15:34:22,853 DEBUG .o.j.EntityManagerFactoryUtils - Line {272} Opening JPA EntityManager
2016-11-14 15:34:22,973 DEBUG e.t.j.p.i.JtaPlatformInitiator - Line {42} No JtaPlatform was specified, checking resolver
2016-11-14 15:34:22,973 DEBUG e.t.j.p.i.JtaPlatformInitiator - Line {42} No JtaPlatform was specified, checking resolver
2016-11-14 15:34:22,974 DEBUG i.JtaPlatformResolverInitiator - Line {33} No JtaPlatformResolver was specified, using default [org.hibernate.engine.transaction.jta.platform.internal.StandardJtaPlatformResolver]
2016-11-14 15:34:22,974 DEBUG i.JtaPlatformResolverInitiator - Line {33} No JtaPlatformResolver was specified, using default [org.hibernate.engine.transaction.jta.platform.internal.StandardJtaPlatformResolver]
2016-11-14 15:34:22,992 DEBUG .i.StandardJtaPlatformResolver - Line {101} Could not resolve JtaPlatform, using default [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2016-11-14 15:34:22,992 DEBUG .i.StandardJtaPlatformResolver - Line {101} Could not resolve JtaPlatform, using default [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2016-11-14 15:34:22,994 DEBUG .JtaTransactionCoordinatorImpl - Line {258} JtaPlatform#retrieveTransactionManager returned null
2016-11-14 15:34:22,994 DEBUG .JtaTransactionCoordinatorImpl - Line {258} JtaPlatform#retrieveTransactionManager returned null
2016-11-14 15:34:22,995 DEBUG .JtaTransactionCoordinatorImpl - Line {223} Unable to access TransactionManager, attempting to use UserTransaction instead
2016-11-14 15:34:22,995 DEBUG .JtaTransactionCoordinatorImpl - Line {223} Unable to access TransactionManager, attempting to use UserTransaction instead
2016-11-14 15:34:22,995 DEBUG .JtaTransactionCoordinatorImpl - Line {241} JtaPlatform#retrieveUserTransaction returned null
2016-11-14 15:34:22,995 DEBUG .JtaTransactionCoordinatorImpl - Line {241} JtaPlatform#retrieveUserTransaction returned null

我没有 persistence.xml 文件.这是我的 spring.xml:

I do not have a persistence.xml file. Here is my spring.xml:

<bean id="entityManagerFactoryEcli"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="commonUnit" />
    <property name="dataSource" ref="dataSourceEcli" />
    <property name="packagesToScan"
        value="org.my.common.portal.domain,eu.cec.justice.common.domain.entity" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="false" />
            <property name="generateDdl" value="false" />
            <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" />
        </bean>
    </property>
    <property name="jpaProperties">
        <props>
            <prop key="javax.persistence.transactionType">jta</prop>
            <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</prop>
            <prop key="hibernate.current_session_context_class">org.hibernate.context.internal.JTASessionContext</prop>
            <prop key="hibernate.cache.use_second_level_cache">true</prop>
            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.cache.region.factory_class">org.my.common.util.ECLICommonEhCacheRegionFactory</prop>
        </props>
    </property>
</bean>

<bean id="entityManagerFactoryCommon"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="portalUnit" />
    <property name="dataSource" ref="dataSourceCommon" />
    <property name="packagesToScan"
        value="eu.cec.justice.common.domain.entity" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="false" />
            <property name="generateDdl" value="false" />
            <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" />
        </bean>
    </property>
    <property name="jpaProperties">
        <props>
            <prop key="javax.persistence.transactionType">jta</prop>
            <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</prop>
            <prop key="hibernate.current_session_context_class">org.hibernate.context.internal.JTASessionContext</prop>
            <prop key="hibernate.cache.use_second_level_cache">true</prop>
            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.cache.region.factory_class">org.my.common.util.ECLICommonEhCacheRegionFactory</prop>
            <prop key="hibernate.ejb.cfgfile">hibernate.cfg.xml</prop>
        </props>
    </property>
</bean>

<bean id="dataSourceCommon" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="$${portal.common.database.jndi}" />
    <property name="resourceRef" value="true" />
</bean>

<bean id="dataSourceEcli" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="$${ecli.database.jndi}" />
    <property name="resourceRef" value="true" />
</bean>

<tx:jta-transaction-manager />
<tx:annotation-driven/>

将以下内容添加到 bean 属性并没有解决我的问题(我也降级到 Hibernate 5.0.0 但问题仍然存在):

Adding the following to the bean properties did not solve my issue (I also downgraded to Hibernate 5.0.0 but still the problem persists):

<prop key="hibernate.transaction.coordinator_class">org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl</prop>

这也不起作用:

<prop key="hibernate.transaction.coordinator_class">jta</prop>

这也删除

<prop key="javax.persistence.transactionType">jta</prop>

但这也失败了.

推荐答案

用户指南:

Hibernate 尝试通过以下方式发现它应该使用的 JtaPlatform使用另一个名为的服务org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver.

Hibernate tries to discover the JtaPlatform it should use through the use of another service named org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver.

如果该分辨率不起作用,或者您希望提供自定义实现你需要指定hibernate.transaction.jta.platform 设置.

If that resolution does not work, or if you wish to provide a custom implementation you will need to specify the hibernate.transaction.jta.platform setting.

尝试通过 hibernate.transaction.jta.platform 配置属性提供底层 JTA 平台.

Try providing the underlying JTA platform via the hibernate.transaction.jta.platform configuration property.

这篇关于更新到 Hibernate 5 后无法访问 TransactionManager 或 UserTransaction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆