Spring Boot 2.0.4 和 WAS Liberty 事务 18.0.0.2 事务管理器问题



我是 WAS Liberty 的新手,正在尝试部署 Spring 启动应用程序。 服务器在启动时引发异常。

[AVERTISSEMENT] 上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.beans.factory.BeanCreation异常:创建类路径资源 [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class] 中定义名称为"entityManagerFactory"的 Bean 时出错:调用 init 方法失败; 嵌套异常是 javax.persistence.PersistenceException: [PersistenceUnit: default] 无法构建 Hibernate SessionFactory;嵌套异常是java.lang.UnsupportedOperationException

问题是Hibernate试图用错误的事务管理器类调用挂起: 由: java.lang.UnsupportedOperationException at org.hibernate.engine.transaction.jta.platform.internal.WebSphereExtendedJtaPlatform$TransactionManagerAdapter.suspend(WebSphereExtendedJtaPlatform.java:131(

这个类是由 Spring 引导在类 HibernateJpaConfiguration 中配置的,该类不包括正确的事务管理器:

私有静态最终字符串[] WEBSPHERE_JTA_PLATFORM_CLASSES = { "org.hibernate.engine.transaction.jta.platform.internal.WebSphereExtendedJtaPlatform", "org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform" };

当我将类更改为org.hibernate.engine.transaction.jta.platform.internal.WebSphereLibertyJtaPlatform时,应用程序启动。这是配置问题还是弹簧引导不支持 WAS Liberty。

感谢您的帮助。

根据此问题,从版本5.2.13和5.3.Beta2开始引入Hibernate的WebSphereLibertyJtaPlatform:https://hibernate.atlassian.net/browse/HHH-11571

如果您使用的是包含WebSphereLibertyJtaPlatform的 Hibernate 版本,并且未显式设置 JTA 平台类属性,那么将自动检测并使用 Liberty 平台。

据我了解,Spring Boot 2.0.4 及其默认的休眠版本(5.2.17(支持 Liberty。然而,正如 Spring Boot 问题 #8926 中所详述的那样,问题是 Spring Boot 2.0.4 覆盖了 Websphere Liberty JTA 实现,否则 Hibernate 会正确设置该实现。

由于各种原因,我被困在 Liberty 16.0.0.4 和 Spring Boot 2.0.4 上,需要找到一种方法来设置正确的 Websphere Liberty JTA 实现。我最终使用像这样HibernatePropertiesCustomizer豆覆盖了hibernate.transaction.jta.platform属性

@Bean
public HibernatePropertiesCustomizer hibernatePropertiesCustomizer() {
return hibernateProperties ->
hibernateProperties.put("hibernate.transaction.jta.platform",
"org.hibernate.engine.transaction.jta.platform.internal.WebSphereLibertyJtaPlatform");
}

最新更新