Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EclipseLink/Examples/JPA/Migration/JBoss

< EclipseLink‎ | Examples‎ | JPA‎ | Migration
Revision as of 16:49, 5 May 2008 by Michael.obrien.oracle.com (Talk | contribs) (EAR Packaging Modifications)

Migrating to JBoss using EclipseLink as JPA provider

  • These instructions are for users wishing to migrate EclipseLink to the JBoss container as well as possibly migrating from another persistence provider such as Hibernate.
  • There is an good example on jboss.org that we will use an example of how to migrate a small container managed web application from using Hibernate to using EclipeLink as the JPA provider.
  • See the RedHat JBoss EJB3 Example.
  • See the JBoss EJB3 example jsfejb3.ear binary.

persistence.xml Modifications

  • The following changes must be done to persistence.xml
  • The fix for EJBTHREE-572 requires that the PersistenceUnit state the JBoss platform using.
    • <property name="eclipselink.target-server" value="org.eclipse.persistence.platform.server.jboss.JBossPlatform"/>
<?xml version="1.0" encoding="UTF-8"?>
<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="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>
        <property name="eclipselink.ddl-generations" value="drop-and-create-tables"/>
        <property name="eclipselink.target-server" value="org.eclipse.persistence.platform.server.jboss.JBossPlatform"/>
        <property name="eclipselink.weaving" value="true"/>
        <property name="eclipselink.logging.level" value="FINEST"/>
      </properties>
    </persistence-unit>
  </persistence>

@EJB Injection/JNDI lookup Modifications

  • The @EJB injection annotation does not currently work outside of the EJB container - for example in the servlet container. The solution is to use a custom JNDI lookup.

EAR Packaging Modifications

  • 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.
  • See 229634: JBoss predeploy workaround
  • Ant static weaving ant task
<target name="run-weaver">
  <taskdef name="weave" classname="org.eclipse.persistence.tools.weaving.jpa.StaticWeaveAntTask">
    <classpath>
      <pathelement path="persistence.jar"/>
      <pathelement path="eclipselink.jar"/>
      <pathelement path="persistence_1_0.xsd"/>
    </classpath>
  </taskdef>

  <!-- process the weaving function, peristenceInfo references persistence.xml -->
  <weave source="build/classes_unweaved"
    target="build/classes"
    persistenceinfo="build/jars/app_unweaved.jar"
    loglevel="FINEST">
  </weave>
</target>
  • Results
    • You should see the following on your Ant log.
C:\wse\w34b\jbossHWEAR>ant -lib c:\wse\w34b\jbossHWEAR -f build.xml
Buildfile: build.xml
clean:
   [delete] Deleting directory C:\wse\w34b\jbossHWEAR\build
compile:
    [mkdir] Created dir: C:\wse\w34b\jbossHWEAR\build\classes
    [mkdir] Created dir: C:\wse\w34b\jbossHWEAR\build\classes_unweaved
    [javac] Compiling 5 source files to C:\wse\w34b\jbossHWEAR\build\classes_unweaved
    [javac] Note: C:\wse\w34b\jbossHWEJB\ejbModule\TodoDao.java uses unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
ejb3jar0:
    [mkdir] Created dir: C:\wse\w34b\jbossHWEAR\build\jars
      [jar] Building jar: C:\wse\w34b\jbossHWEAR\build\jars\app_unweaved.jar
run-weaver:
    [weave] [EL Finer]: 2008.05.05 16:30:41.216--ServerSession(29857804)--Thread(Thread[main,5,main])--Searching for default mapping file in file:/C:/wse/w34b/jbossHWEAR/build/jars/app_unweaved.jar
    [weave] [EL Finer]: 2008.05.05 16:30:41.246--ServerSession(29857804)--Thread(Thread[main,5,main])--Found a default mapping file at jar:file:/C:/wse/w34b/jbossHWEAR/build/jars/app_unweaved.jar!/META-INF/orm.xml for root URL file:/C:/wse/w34b/jbossHWEAR/build/jars/app_unweaved.jar
    [weave] [EL Config]: 2008.05.05 16:30:41.878--ServerSession(29857804)--Thread(Thread[main,5,main])--The table name for entity
[Todo] is being defaulted to: TODO.
    [weave] [EL Config]: 2008.05.05 16:30:41.891--ServerSession(29857804)--Thread(Thread[main,5,main])--The discriminator column name for the root inheritance class [class Todo] is being defaulted to: DTYPE.
    [weave] [EL Config]: 2008.05.05 16:30:41.928--ServerSession(29857804)--Thread(Thread[main,5,main])--The column name for element [public java.lang.String Todo.getDescription()] is being defaulted to: DESCRIPTION.
    [weave] [EL Config]: 2008.05.05 16:30:41.937--ServerSession(29857804)--Thread(Thread[main,5,main])--The column name for element [public java.lang.String Todo.getTitle()] is being defaulted to: TITLE.
    [weave] [EL Finer]: 2008.05.05 16:30:41.950--ServerSession(29857804)--Thread(Thread[main,5,main])--Class [Todo] registered to be processed by weaver.
    [weave] [EL Finest]: 2008.05.05 16:30:41.974--ServerSession(29857804)--Thread(Thread[main,5,main])--Begin weaver class transformer processing class [Todo].
    [weave] [EL Finest]: 2008.05.05 16:30:42.020--ServerSession(29857804)--Thread(Thread[main,5,main])--Weaved persistence (PersistenceEntity) [Todo].
    [weave] [EL Finest]: 2008.05.05 16:30:42.029--ServerSession(29857804)--Thread(Thread[main,5,main])--Weaved change tracking (ChangeTracker) [Todo].
    [weave] [EL Finest]: 2008.05.05 16:30:42.040--ServerSession(29857804)--Thread(Thread[main,5,main])--Weaved fetch groups (FetchGroupTracker) [Todo].
    [weave] [EL Finest]: 2008.05.05 16:30:42.053--ServerSession(29857804)--Thread(Thread[main,5,main])--End weaver class transformer processing class [Todo].
war:
      [war] Building war: C:\wse\w34b\jbossHWEAR\build\jars\app.war
ejb3jar:
      [jar] Building jar: C:\wse\w34b\jbossHWEAR\build\jars\app.jar
ear:
      [ear] Building ear: C:\wse\w34b\jbossHWEAR\build\jars\jsfejb3.ear
deploy:
     [copy] Copying 1 file to C:\opt\jboss422\server\default\deploy
main:
BUILD SUCCESSFUL
Total time: 3 seconds

Back to the top