Migrating from Hibernate to EclipseLink within the JBoss JSFEJB3 Example

These instructions are for users wishing to use EclipseLink as the JPA provider in place of Hibernate in the JBoss container.

The scope of this document is a description of the required static weaving workaround for EJBTHREE-572 using the JBoss JSFEJB3 example as reference. See the JPA Migration page for an overall migration example.

The EJB3 example on jboss.org will be used as a common open-source example of how to migrate a small container managed web application from using Hibernate to using EclipeLink as the JPA provider.

Modified persistence.xml

<xmlversion="1.0"encoding="UTF-8"?><persistenceversion="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-unitname="helloworld"><provider>org.eclipse.persistence.jpa.PersistenceProvider</provider><jta-data-source>java:/DefaultDS</jta-data-source><!-- Entities must be specified for EclipseLink weaving --><class>Todo</class><properties><propertyname="eclipselink.target-database"value="HSQL"/><propertyname="eclipselink.ddl-generation"value="drop-and-create-tables"/><propertyname="eclipselink.ddl-generation.output-mode"value="database"/><propertyname="eclipselink.target-server"value="JBoss"/><propertyname="eclipselink.weaving"value="false"/><propertyname="eclipselink.logging.level"value="FINEST"/></properties></persistence-unit></persistence>

The following changes must be done to persistence.xml

Set target-server

The fix for EJBTHREE-572 requires that the PersistenceUnit state the JBoss platform using the target-server property. We recommend the short name JBoss (but the full package name org.eclipse.persistence.platform.server.jboss.JBossPlatform is supported).

See org.eclipse.persistence.config.TargetServer for a list of container platforms supported.

<propertyname="eclipselink.target-server"value="JBoss"/>

Set target-database

To continue to use the HSQL (Hypersonic) Database all you need to do is define the target-database in the persistence unit, we recommend the short name HSQL (but the full package name org.eclipse.persistence.platform.database.HSQLPlatform is supported).

See org.eclipse.persistence.config.TargetDatabase for a list of databases supported.

<propertyname="eclipselink.target-database"value="HSQL"/>

Drop/Create Database

The tables will be automatically dropped and created by EclipseLink with the following 2 properties in the persistence unit. For production environments you would normally already have the schema setup on the database, so using the following schema generation properties will erase any previous existing tables and are normally used for example/demo purposes.

JTA Datasource Configuration

No changes are required in the deploy directory of JBoss 4.2.2 out of the box to run HSQL.

@EJB Injection/JNDI lookup Modifications

The @EJB injection annotation does not currently work outside of the JBoss EJB container - for example in the servlet container. The solution is to use a custom JNDI lookup which is not in standard JNDI naming format such as "java:comp/env/ejb/jsfejb3/TodoDao" - this code is already on the session DAO bean.

Static Weaving / EAR Packaging Modifications

This example does not require weaving - this section is for reference and can be skipped.

Dynamic weaving (byte-code instrumentation) is not currently available in JBoss 4.2.2 because of JIRA EJBTHREE-572. Our workaround is to statically weave the entities by running the following Ant task before creating your EJB jar during EAR packaging. You must use the statically weaved classes if you would like to use LAZY 1-1 and many-1 functionality.