5

I want to not use the built in Websphere 7 jpa plugin, instead use an application WEB-INF/lib/open-jpa 2 and a proprietary persistence provider. I cannot install the OSGI and JPA 2 feature pack for Websphere.

Originally, I was getting a sax parse error simply trying to load the persistence.xml (version="2" not supported). The error was thrown by a class in open-jpa 1.2.3. When I run websphere/appserver/bin/wsjpaversion.bat, the open-jpa 1.2.3 jar is displayed. By default it overrides the open-jpa 2 jar in the app. I created a shared library containing the open-jpa 2 jar with this config option checked: 'Use an isolated class loader for this shared library'. I set my application classloader to load parent last and assigned it the new shared library resource. The 'version 2' error is gone, but there is another problem. When I try to initialize an EntityManager I get an error:

Caused by: javax.persistence.PersistenceException: Failed to load provider from META-INF/services
    at javax.persistence.spi.PersistenceProviderResolverHolder$DefaultPersistenceProviderResolver.getPersistenceProviders(PersistenceProviderResolverHolder.java:121)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:91)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
    ... 2 more
Caused by: java.lang.ClassCastException: com.ibm.websphere.persistence.PersistenceProviderImpl incompatible with javax.persistence.spi.PersistenceProvider
    at javax.persistence.spi.PersistenceProviderResolverHolder$DefaultPersistenceProviderResolver.getPersistenceProviders(PersistenceProviderResolverHolder.java:110)
    ... 11 more

One more detail: inside the persistence.xml, the provider element is set to the proprietary PersistenceProviderImpl not the default Websphere persistence provider. So where is this websphere default coming from and how do I prevent it? (another important note: when I remove persistence.xml completely, I get the same error)

Thank you

Morgan Dowell
  • 267
  • 5
  • 11

1 Answers1

4

Without installing the feature pack, you're fighting a losing battle. While it is possible to plug in your own JPA implementation, it is not possible to do that with JPA API — so WAS 7 ties you to the 1.0 version of JPA (see, for example, here how this is done — no class loader policy juggling will change that, though it seems tempting at first).

MaDa
  • 10,511
  • 9
  • 46
  • 84
  • You're right it was not worth the trouble. Websphere 7 has jpa 1 too interwoven. I think it is possible if you make your own persistence provider resolver and exclude the default websphere persistence provider which is loaded from the classpath, but for me it was not worth the trouble. – Morgan Dowell Oct 14 '11 at 02:02
  • 2
    @MorganDowell This is the main reason why our company sticks to JPA 1.0, even in the new applications - as our servers host many apps, old and new at the same time, we'd have to set up entirely different server groups just for applications using JPA 2, which is not feasible for financial reasons. – MaDa Oct 14 '11 at 07:13