Reputation: 155
I am having issues with getting my application running with JPA 2.0 on WAS 7.0. I am using RSA 8.5 for development. I am using Hibernate as the provider.
Here is what I have done so far:
I configured my project with JPA 2.0 facet.
added all the hibernate "required" jars and the jpa jar to the build path as well as in the manifest entry.
I followed this article: Alternate JPA Providers in WebSphere Application Server and I changed the default persistence provider via admin console, and I am seeing these lines in the logs at server startup:
[12/6/13 9:36:20:529 EST] 00000000 JPAComponentI I CWWJP0026I: The Java Persistence API (JPA) component is initializing.
[12/6/13 9:36:20:537 EST] 00000000 JPAComponentI I CWWJP0006I: The org.hibernate.ejb.HibernatePersistence class is loaded as the default Java Persistence API (JPA) provider.
This is my application's persistence.xml:
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="biReconWeb"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/> <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup"/>
In the server, I created a shared library with the following jars and created a "application first" class loader referencing this shared lib:
antlr-2.7.7.jar
hibernate-commons-annotations-4.0.2.Final.jar
hibernate-core-4.2.7.SP1.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
javassist-3.18.1-GA.jar
jboss-logging-3.1.0.GA.jar
jboss-transaction-api_1.1_spec-1.0.1.Final.jar
hibernate-entitymanager-4.2.7.SP1.jar
When I deploy the application, I am getting this error:
> Caused by: org.xml.sax.SAXParseException: cvc-complex-type.3.1: Value
> '2.0' of attribute 'version' of element 'persistence' is not valid
> with respect to the corresponding attribute use.Attribute 'version'
> has a fixed value of '1.0'.
If I change the persistence version to 1.0, the application starts OK. But I want to use JPA 2.0, can you tell me what I am doing wrong?
PS: One thing I have not done is I have not applied any JPA feature packs to my WAS (version 7.0.0). Could this be the issue?
Upvotes: 3
Views: 2252
Reputation: 22441
It looks like the JPA 1.0 libraries of WAS (loaded by the parent classloader) are trying to read the persistence.xml
of your webapp and get confused by the version.
According to this post (in French), you have to either install the OSGI & JPA 2.0 Feature Pack, or move your persistence.xml
somewhere else than under META-INF
so the JPA 1.0 libraries don't find it. You then need to load your persistence.xml
using an alternative way, either programmatically or through Spring.
Upvotes: 2