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.