views:

72

answers:

3

Hi,

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

+2  A: 

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

Bozho
Wow, I must admit I'm surprised. I don't even understand how this can work (I mean, without breaking container managed JPA).
Pascal Thivent
Pascal Thivent well, I _think_ the jars put there are preferred instead of the container libs. Not that I've actually used that (used Glassfish 2 years ago), but thought I can suggest it. :)
Bozho
+1  A: 

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"&gt;
<sun-web-app error-url="">
    <class-loader delegate="false"/>
</sun-web-app>
Pascal Thivent
hm, someone has downvoted this.. here comes a correction.
Bozho
A: 

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!

Jay Shark