Upgrade Glassfish v2 to JPA 2.0?
Asked Answered
D

4

7

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

Disabuse answered 1/10, 2010 at 15:55 Comment(1)
Would upgrading to Glassfish 3 be an option?Sperrylite
S
4

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

Sarrusophone answered 1/10, 2010 at 16:4 Comment(3)
Wow, I must admit I'm surprised. I don't even understand how this can work (I mean, without breaking container managed JPA).Electrify
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. :)Sarrusophone
This doesn't work for me. Did you mean: $GLASSFISH_HOME/domains/domain1/lib/endorsed or $GLASSFISH_HOME/lib/endorsed? Thanks.Stagger
D
1

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!

Disabuse answered 3/10, 2010 at 21:35 Comment(0)
E
0

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>
Electrify answered 1/10, 2010 at 17:31 Comment(1)
This will not work for this case, per the Glassfish documentation: "For a number of packages, including java.* and javax.*, symbol resolution is always delegated to the parent class loader regardless of the delegate setting. This prevents applications from overriding core Java runtime classes or changing the API versions of specifications that are part of the Java EE platform."Britten
N
0

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

Naevus answered 31/8, 2012 at 14:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.