gpt4 book ai didi

java - JTA 与 Spring 4.2 和 Hibernate 5.0(JPA 接口(interface))

转载 作者:太空宇宙 更新时间:2023-11-04 12:38:55 24 4
gpt4 key购买 nike

最近,我工作的其他开发人员已经将我们老化的 Hibernate 依赖项从 3.0 升级了。 (也许 3.5?)到 5.0。不久之后他们注意到我们遇到了 DBCP 检测到的连接泄漏。我的任务是尝试诊断原因。

我决定尝试升级 Spring,因为它被忽略了,我已经替换了所有相关的 jar 文件以从 3.0.5 升级到 4.2.5,现在看到了一个我无法弄清楚的不同问题。

根据 jar 中的 MANIFEST.MF 文件,我们使用 JOTM 进行 JTA,目前使用的是 2.0.11 版本。在此版本中,结合更新的 Hibernate 和 Spring,我看到以下内容:

org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException: Could not obtain JOTM transaction manager instance
at org.hibernate.engine.transaction.jta.platform.internal.JOTMJtaPlatform.locateTransactionManager(JOTMJtaPlatform.java:31)
at org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform.retrieveTransactionManager(AbstractJtaPlatform.java:92)
at org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform.getTransactionManager(AbstractJtaPlatform.java:98)
at org.hibernate.engine.transaction.jta.platform.internal.TransactionManagerBasedSynchronizationStrategy.canRegisterSynchronization(TransactionManagerBasedSynchronizationStrategy.java:39)
at org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform.canRegisterSynchronization(AbstractJtaPlatform.java:131)
at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.pulse(JtaTransactionCoordinatorImpl.java:141)
at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.<init>(JtaTransactionCoordinatorImpl.java:92)
at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl.buildTransactionCoordinator(JtaTransactionCoordinatorBuilderImpl.java:28)
at org.hibernate.internal.SessionImpl.<init>(SessionImpl.java:274)
at org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl.openSession(SessionFactoryImpl.java:1327)
at org.hibernate.jpa.internal.EntityManagerImpl.internalGetSession(EntityManagerImpl.java:133)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:174)
at org.hibernate.jpa.internal.EntityManagerImpl.<init>(EntityManagerImpl.java:83)
at org.hibernate.jpa.internal.EntityManagerFactoryImpl.internalCreateEntityManager(EntityManagerFactoryImpl.java:319)
at org.hibernate.jpa.internal.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:286)
at sun.reflect.GeneratedMethodAccessor399.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.invokeProxyMethod(AbstractEntityManagerFactoryBean.java:407)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean$ManagedEntityManagerFactoryInvocationHandler.invoke(AbstractEntityManagerFactoryBean.java:560)
at com.sun.proxy.$Proxy243.createEntityManager(Unknown Source)
at org.springframework.orm.jpa.EntityManagerFactoryUtils.doGetTransactionalEntityManager(EntityManagerFactoryUtils.java:285)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:255)
at com.sun.proxy.$Proxy271.createQuery(Unknown Source)
at com.company.app.persistence.AbstractEntityGroupDAO.getSomething(AbstractEntityGroupDAO.java:80)
at com.company.app.servicehealth.StatusServiceDAO.retrieveStatusServices(StatusServiceDAO.java:259)
at com.company.app.servicehealth.StatusServiceDAO.queryForStatusServices(StatusServiceDAO.java:255)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
at com.sun.proxy.$Proxy273.queryForStatusServices(Unknown Source)
at com.company.app.servicehealth.ServiceHealthStatusImpl$1.doInTransaction(ServiceHealthStatusImpl.java:142)
... 50 more
Caused by: java.lang.NullPointerException
at org.hibernate.engine.transaction.jta.platform.internal.JOTMJtaPlatform.locateTransactionManager(JOTMJtaPlatform.java:26)
... 90 more

经检查,在我看来,serviceRegistry()serviceRegistry().getService( ClassLoaderService.class ) 返回 null。 (下面是该方法的内容)

public static final String TM_CLASS_NAME = "org.objectweb.jotm.Current";
public static final String UT_NAME = "java:comp/UserTransaction";

@Override
protected TransactionManager locateTransactionManager() {
try {
final Class tmClass = serviceRegistry().getService( ClassLoaderService.class ).classForName( TM_CLASS_NAME );
final Method getTransactionManagerMethod = tmClass.getMethod( "getTransactionManager" );
return (TransactionManager) getTransactionManagerMethod.invoke( null, (Object[]) null );
}
catch (Exception e) {
throw new JtaPlatformException( "Could not obtain JOTM transaction manager instance", e );
}
}

我该如何解决这个问题?我对 Spring 完全陌生,我只能说我们使用的是 JPA (EntityManager),而不是 Hibernate 的 SessionFactory。

最佳答案

听起来像是依赖性问题。在 POM 依赖关系层次结构中(假设您使用 Maven),检查类路径中是否有多个版本的 Hibernate。您可能需要考虑尝试 Hibernate 4.3.11.Final 而不是 5.x

关于java - JTA 与 Spring 4.2 和 Hibernate 5.0(JPA 接口(interface)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37030720/

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