Question

I'm trying to use Hibernate 3.5.5 with Spring HibernateJpaVendorAdapter on Glassfish V2 but I'm getting the following exception when the Spring context is initialised:

java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode;

at org.hibernate.ejb.util.LogHelper.logPersistenceUnitInfo(LogHelper.java:39) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:517) at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)

The problem is that Glassfish V2 uses JPA1.0 which is loaded on the server classpath before hibernate-jpa-2.0-api-1.0.0.Final.jar which ships with Hibernate. JPA 1.0 doesn't have a getSharedCacheModel method in PersistenceUnitInfo but JPA 2.0 does.

Is there any way of upgrading Glassfish V2 to use JPA 2.0 (or any other solution to this problem)?

Cheers,

J

Was it helpful?

Solution

You can try putting the JPA 2.0 jar in the /domain/lib/endorsed dir

OTHER TIPS

Thanks for the feedback guys. Putting the jpa jar in /domain/lib/endorsed worked for me.

Setting...

<sun-web-app error-url="">
    <class-loader delegate="false"/>
</sun-web-app>

...did not work for me although that could just be because the classes are part of javax.

I also tried stripping out Spring's JPATemplate and using the JPA @PersistenceContext EntityManager directly - this caused all sorts of problems though. Glassfish v2 + Spring + Hibernate are not friends!

To my knowledge, it is not possible to upgrade Java EE 5 containers core JPA libraries by simply replacing libraries and to use a container managed JPA 2.0 EntityManager.

However, it should be possible to use a JPA 2.0 implementation with the JPA 2.0 API library provided at the application level and to use an application managed JPA 2.0 EntityManager.

To try the second approach with GlassFish v2, you'll need to switch off classloader delegation (so that application libraries will be used first). This can be configured in a sun-web.xml that you'll packaged under WEB-INF:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app
        PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 8.1 Servlet 2.4//EN"
        "http://www.sun.com/software/appserver/dtds/sun-web-app_2_4-1.dtd">
<sun-web-app error-url="">
    <class-loader delegate="false"/>
</sun-web-app>

Glassfish 2.1 don't support JPA 2, I downloaded the JPA 2 version and pasted into the $GLASSFISH_HOME/lib/endorsed/ directory, and pasted to the commons-loggin1.1.jar, and this works for me.

It looks like this:

/glassfish/lib/endorsed$ ls
activation.jar
openjpa-all-2.0.1.jar
commons-logging-1.1.jar
webservices-api.jar

http://glassfish.java.net/public/comparing_v2_and_v3.html
http://openjpa.apache.org/downloads.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top