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.
I don't tried your example but was thinking about the descriptor persistence.xml.
ReplyDeleteThe 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 :).
Sorry missed the lines at the end about descriptor :) now is clear why is versione 1.0.
ReplyDeleteHi I'm using WL 10.3.0.0 and every time I try to add (to my weblogic.xml)
ReplyDeletejavax.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?
Lorenzo,
ReplyDeleteYou have to add this to your weblogic-application.xml ... it's in the ear!
Rgds
Markus
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
ReplyDeletehttp://javaiscoool.blogspot.com/2012/12/deploy-jpa20-application-on-weblogic1033.html