1

I have a legacy application which I am migrating to java 11. After migrating and doing relevant changes, if I run my application is eclipse, it runs fine and gives the desired output. Problem comes when I build the jar and deploy it in an test environment. When I execute the process it gives the fatal error with the below trace while getting the bean. I searched around and tried whatever was suggested( clean build and deploy, removing conflicting dependencies), but I still get this error while running it where the jar is deployed. Confusion is it is working in eclipse which is making it tough to debug the error.

I am using hibernate 5.4.24 and Spring 5.3.1.

Any help to resolve this would be highly appreciated.

CAUSE               java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'LIQBeanFactory' defined in URL [jar:file:/E:/QNBLIQ75/Client/sdk-post/qnb_liq_sdk_outbound.jar!/beanRefFactory.xml]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.context.support.ClassPathXmlApplicationContext]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'LIQSessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Map;

Caused by: java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Map;
at org.hibernate.engine.query.spi.QueryPlanCache.<init>(QueryPlanCache.java:92)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:261)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:469)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:616)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:600)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1847)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1784)
... 231 more

Edited: I am coverted it into a maven project and when I run now, I get the exact error into eclipse debugguer. Below is my dependencies from POM.xml, can you please suggest if there is any conflicts:

 <dependencies>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-collections4</artifactId>
      <version>4.4</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <version>2.14.0</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>com.oracle.database.jdbc</groupId>
      <artifactId>ojdbc10</artifactId>
      <version>19.8.0.0</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>javax.jws</groupId>
      <artifactId>javax.jws-api</artifactId>
      <version>1.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-bundle</artifactId>
      <version>3.0.0-milestone2</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>5.3.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>5.3.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>5.3.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>5.3.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>5.3.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>5.4.24.Final</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.hibernate.common</groupId>
      <artifactId>hibernate-commons-annotations</artifactId>
      <version>5.1.2.Final</version>
      <scope>compile</scope>
    </dependency>
</dependencies>
M. Deinum
  • 115,695
  • 22
  • 220
  • 224
Sourav Roy
  • 63
  • 2
  • 9
  • Does this answer your question? [java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Properties](https://stackoverflow.com/questions/43309946/java-lang-nosuchmethoderror-org-hibernate-engine-spi-sessionfactoryimplementor) – SternK Dec 17 '20 at 08:34
  • Probably an incompatible version somewhere in your classpath. – M. Deinum Dec 17 '20 at 08:36
  • @SternK Thanks - I will refer the link. But I am facing this issue while runtime when the jar is deployed, its working fine when I run my code in eclipse. I have also checked for any incompatible versions in classpath but could not detect any. – Sourav Roy Dec 17 '20 at 08:50
  • Do you have upgraded the version of Hibernate from a 4.x version? If so, please check if you have any imports refering to ```org.springframework.orm.hibernate4``` and change them to ```org.springframework.orm.hibernate5``` Please let me know if this solves your problem :) – Kaj Hejer Dec 17 '20 at 09:49
  • @kal Hejer - I have upgraded hibernate to 5.x and there is no import related to lower version except there is a reference in .hbm files referring the dtd mapping as "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" which I m sure does not cause this issue. And for sesssion factory I am calling the class - org.springframework.orm.hibernate5.LocalSessionFactoryBean – Sourav Roy Dec 17 '20 at 10:27
  • assuming you are using maven use `mvn dependency:tree` to list all dependencies and find the culprit. – M. Deinum Dec 17 '20 at 10:43
  • @M.Deinum unfortunately the project is not on maven, its a legacy app and needs to migrate to java 11 compatible platform. Is there a way in such cases to determine conflicting dependency jars. – Sourav Roy Dec 17 '20 at 10:56
  • What are you on? How are you adding libraries? Get a list of all libraries and post them here. – M. Deinum Dec 17 '20 at 11:49
  • @M.Deinum I have converted my project to maven. The dependencies are added above. Please can you suggest on that? – Sourav Roy Dec 17 '20 at 20:51
  • How are you running this application? – M. Deinum Dec 18 '20 at 06:47
  • @M.Deinum using a Debug Configuration as its an interface of an application. The transaction in the main application triggers this code and the error occurs while executing this new ClassPathXmlApplicationContext("classpath*:beanRefFactory.xml"); – Sourav Roy Dec 21 '20 at 09:19
  • You shouldbn't be even creating a new application context... Also you are deploying to a test environment, which environment/server is that? – M. Deinum Dec 21 '20 at 09:21
  • @M.Deinum windows servers, Tomcat 9 – Sourav Roy Dec 21 '20 at 10:34
  • @M.Deinum the code was written in spring 3 and I am trying to migrate it to spring 5. ClassPathXmlApplicationContext("classpath*:beanRefFactory.xml"); is part of the old code base. Do you suggest in changing the way to get beans from the application context? – Sourav Roy Dec 21 '20 at 10:36
  • @SouravRoy Did your issue resolved? I have version 5.6.14 and getting the same issue. Also, I don't have a maven but only Ant. So, it's not possible to manage dependency with maven. could you please let me know how you resolved this? I am migrating for hibernate 3 to hibernate 5 – Raj Dec 22 '22 at 10:21

0 Answers0