0

I am using Resin 3.1.9 to run Java Web Application with JPA 2.1. I have put libraries (JAR) on my WEB-INF/lib folder, and I have include them to resin.conf by this:

<class-loader>
    <tree-loader path="${resin.root}/webapps/myapp/WEB-INF/lib"/>
</class-loader>

If I didn't include it in resin.conf, I saw an exception about failed to load some classes (even when in first loading on home page). OK now when loading home page it is no problem, but I wonder when I try to add some record (via CRUD form), it said:

java.lang.NoClassDefFoundError: javax/persistence/spi/PersistenceProvider

In fact, class javax.persistence.spi.PersistenceProvider is absolutely exist in "WEB-INF/lib" which is in file "hibernate-jpa-2.1-api-1.0.0.Final.jar"

Is there any debugging step how to check loaded libraries during Resin startup? Or is there something wrong in my resin.conf?

danisupr4
  • 815
  • 1
  • 9
  • 22

1 Answers1

0

EDIT After some investigations, it seems my suggestion of an SPI problem is wrong: double JPA implementations not properly declared raise a PersistenceException.

This is probably not a class loading problem but rather an SPI problem. Have you checked the provider element for hibernate in your persistence.xml ? This should be something like this :

<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

Perhaps you should also mention an SPI declaration, but you should only do so if you have multiple implementations available. This is probably the case because of the JPA implementation of your Java EE web profile server. In such a case, you should add a

services
folder in your
META-INF
folder and create a
javax.persistence.spi.PersistenceProvider
text file inside.

This file should list the two persistence provider implementations (hibernate and the one included in Resin, I don't find it in the documentation).

bdulac
  • 1,686
  • 17
  • 26
  • Are you sure it is not about class loading? Because in the exception it also said `java.lang.ClassNotFoundException: javax.persistence.spi.PersistenceProvider` – danisupr4 Oct 14 '14 at 08:20
  • I am not sure, I guess: you say the interface is available for class loading. To check if the class really available, you have to do it by yourself and not rely on the platform [Class.forName("javax.persistence.spi.PersistenceProvider")]. If the class loads properly, this is it: the SPI has a special way of class-loading and in the case where you have multiple implementations there is some configuratin to do. – bdulac Oct 14 '14 at 09:39
  • My clue is wrong, this is probably a real ClassLoader problem: I tried a solution with multiple JPA implementations without declration and I got a PersistenceException, not a ClassNotFoundException. Please let me know about the Class#forName result... – bdulac Oct 14 '14 at 11:49