1

I am a newbie in WAS Liberty and trying to deploy a spring boot application. The sever is throwing an exception at startup.

[AVERTISSEMENT] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is java.lang.UnsupportedOperationException

The problem is that Hibernate is trying to call a suspend with a wrong transaction manager class : Caused by: java.lang.UnsupportedOperationException at org.hibernate.engine.transaction.jta.platform.internal.WebSphereExtendedJtaPlatform$TransactionManagerAdapter.suspend(WebSphereExtendedJtaPlatform.java:131)

This class was configured by Spring Boot in the class HibernateJpaConfiguration which does not include the proper transaction manager :

private static final String[] WEBSPHERE_JTA_PLATFORM_CLASSES = { "org.hibernate.engine.transaction.jta.platform.internal.WebSphereExtendedJtaPlatform", "org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform" };

when i change the class to org.hibernate.engine.transaction.jta.platform.internal.WebSphereLibertyJtaPlatform the application starts. Is this a configuration issue or is spring boot not supporting WAS Liberty.

Thanks for your help.

Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
mmbouraoui
  • 33
  • 5
  • As mentioned in https://github.com/spring-projects/spring-boot/issues/14178 an issue is already opened in spring boot for this. Refer to https://github.com/spring-projects/spring-boot/issues/8926 – mmbouraoui Aug 23 '18 at 09:12

2 Answers2

1

The WebSphereLibertyJtaPlatform was introduced to Hibernate as of version 5.2.13 and 5.3.Beta2 according to this issue: https://hibernate.atlassian.net/browse/HHH-11571

If you are using a version of Hibernate that contains the WebSphereLibertyJtaPlatform and the JTA platform class property is not explicitly set, then the Liberty platform will be automatically detected and used.

Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
0

It is my understanding that Spring Boot 2.0.4 and it's default Hibernate version (5.2.17) supports Liberty. The problem however is, as detailed in Spring Boot issue #8926, that Spring Boot 2.0.4 overrides the Websphere Liberty JTA implementation that would otherwise be correctly set by Hibernate.

For various reasons I am stuck with Liberty 16.0.0.4 and Spring Boot 2.0.4 and needed to find a way to set the correct Websphere Liberty JTA implementation. I ended up overriding the hibernate.transaction.jta.platform property using a HibernatePropertiesCustomizer bean like so

@Bean
public HibernatePropertiesCustomizer hibernatePropertiesCustomizer() {
    return hibernateProperties ->
            hibernateProperties.put("hibernate.transaction.jta.platform",
                    "org.hibernate.engine.transaction.jta.platform.internal.WebSphereLibertyJtaPlatform");
}
Misantorp
  • 2,606
  • 1
  • 10
  • 18