JPA 2.0 and Oracle Weblogic 10.3.2.0 (11g)

Markus Eisele
5
Everything is about JEE 6 these days. And believe me, I really love the new spec. What I am really missing is the JEE 6 version of a Weblogic server. Anyway, I am still giving parts of the spec some tries on the latest version. Up to now, this was not too successfull. JSF 2.0 is not working. Next was to give JPA 2.0 a try. The guys from the EclipseLink project already did this for me. There is a complete analysis about the possible solutions online in the EclipseLink wiki space. You basically have two differnt options available at the moment to use even parts of the new JPA 2.0.

Change your server/domain install to use new versions of javax.persistence.* and org.eclipse.persistence.* or bundle the related libraries with your application. Both cases have some drawbacks at the moment.

I decided to give it a try anyway and just wanted to give you a more detailed explanation, of what to do to make the second approach work.

First is to get the latest EclipseLink 2.x and the JPA 2.0 API libraries. I was using javax.persistence_2.0.0.v200911041116.jar and eclipselink.jar both taken from the eclipselink-2.0.0.v20091127-r5931.zip download.

Now you have to setup an EAR and a WAR project within your favorite IDE. I am using the Oracle Enterprise Pack for Eclipse (OEPE) for this. Add both jars to the APP-INF/lib folder of your EAR project and change the weblogic-application.xml descriptor by adding the following lines to it:

<wls:prefer-application-packages>
<wls:package-name>org.eclipse.persistence.*</wls:package-name>
<wls:package-name>javax.persistence.*</wls:package-name>
/wls:prefer-application-packages>

Now you have to add a src/META-INF folder to your WAR project. Create a MANIFEST.MF file with the following two lines:

Manifest-Version: 1.0
Class-Path: javax.persistence_2.0.0.v200911041116.jar eclipselink.jar

Place your persistence.xml in the same place. Mine looks like this:

<persistence version="1.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_1_0.xsd">
<persistence-unit name="example" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>ds/localJTA</jta-data-source>
<class>...</class>
<properties>
<property name="eclipselink.target-server" value="WebLogic_10"/>
<property name="eclipselink.logging.level" value="FINEST"/>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
</properties>
</persistence-unit>
</persistence>

This is basically everything. Now you can start to put your Entities and business in your webapplication. But remeber to:
- add every Entity as a <class>...</class> entry to your persistence.xml as dynamic class weaving will not work with this approach.
- Reorder the Java Build Path of your IDE to have the EAR libraries in front of any server libraries. Only this way, you will be able to use the new API features.
- As the schema of the persistence.xml states, you are only able to use JPA 1.0 declarations in it.
- Injecting the EntityManager will not work. You have to get it manually from javax.persistence.Persistence like this:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("example");
EntityManager em = emf.createEntityManager();


After all, this is not a full blown approach to JPA 2.0. But better than nothing. Let's hope for a early preview of EclipseLink 2.0 on Weblogic Server.

Post a Comment

5Comments

  1. I don't tried your example but was thinking about the descriptor persistence.xml.

    The first line, did should not refer to the 2.0 version of the persistence.xml schema? like this:


    Can i use your solution without a WAR? updating the Manifest in a EAR project with only EJBs?

    Thanks in advance for reply if you can :).

    ReplyDelete
  2. Sorry missed the lines at the end about descriptor :) now is clear why is versione 1.0.

    ReplyDelete
  3. Hi I'm using WL 10.3.0.0 and every time I try to add (to my weblogic.xml)

    javax.persistence.*


    The server refuse to deploy my application because of a parse error, on the xml.

    Do i need to incluse some specific XML Namespace or DTD to support this tag?

    ReplyDelete
  4. Lorenzo,
    You have to add this to your weblogic-application.xml ... it's in the ear!

    Rgds
    Markus

    ReplyDelete
  5. I recently fixed this problem on weblogic 10.3.3 which is JPA1.0 complient I believe it will also work in your case have a look at below blog post

    http://javaiscoool.blogspot.com/2012/12/deploy-jpa20-application-on-weblogic1033.html

    ReplyDelete
Post a Comment