1
votes

I am running Spring 3 + Hibernate 4 jpa and mysql successfully if i deploy war inside tomcat 7 but If I deploy same war inside Tomee plus 1.7.2 then I get following exception.

Caused by: java.lang.ClassNotFoundException: org.hibernate.cache.QueryResultsRegion
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
    at org.apache.tomee.catalina.LazyStopWebappClassLoader.loadClass(LazyStopWebappClassLoader.java:171)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)

I find that this class is part of hibernate 3.3 but I am using hibernate 4.2.

I copied hibernate-core-4.2.0.Final.jar, hibernate-ehcache-4.2.0.Final.jar,cglib-2.2.2.jar,hibernate-jpa-2.0-api-1.0.1.Final.jar,hibernate-commons-annotations-4.0.1.Final.jar,hibernate-entitymanager-4.2.0.Final.jar,hibernate-validator-4.2.0.Final.jar,ehcache-core-2.4.3.jar,spring-data-commons-core-1.3.0.RELEASE.jar,spring-data-jpa-1.1.0.RELEASE.jar,spring-jdbc-3.0.7.RELEASE.jar,spring-orm-3.1.2.RELEASE.jar to /lib folder also. These jars also part of war.

persistence.xml is:

<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">      <provider>org.hibernate.ejb.HibernatePersistence</provider>
</persistence-unit>
1
Did you try the guide in my answer in the meantime?MWiesner

1 Answers

1
votes

Something in your application or a referenced third-party library is still referencing the org.hibernate.cache.QueryResultsRegion class when the WebappClassLoader implementation tries to bring up your Web-project.

Most likely this is due to the outdated JAR of spring-orm-3.1.2.RELEASE.jar. You should be able to overcome this by upgrading your Spring version to at least 4.0, but better go 4.1/4.2 in the long run.

When inspecting the dependencies of spring-data-commons-core-1.3.0.jar I found, that it should be compatible with Spring 4.0.x - no guarantee for 4.1/4.2.

Another tricky JAR could be spring-data-jpa-1.1.0.RELEASE.jar as it is outdated (released in May 2012) and is available in version 1.9.x already. Try to figure out constellations that date from at least 2014 or better 2015.

My suggestion are:

  1. Upgrade Spring at least to version 4.0.x.
  2. Check your own class files for references of direct imports of that conflicting runtime class.
  3. Check other configuration files that might be present in your project, like Spring application/module contexts that make use of ORM classes (like ehcache).
  4. (optional) Try to upgrade to Spring 4.1/4.2 gradually if the class loading error should have been solved. Test your setup alongside in a functional manner.

Hope it helps.