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 23:46, 5 May 2008 by Michael.obrien.oracle.com (Talk | contribs) (Set target-database)

Migrating to JBoss using EclipseLink as JPA provider

  • *Warning: These instructions started on 20080505 are under construction for the next couple days
  • 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.
  • 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.

persistence.xml Modifications

<?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" transaction-type="JTA" >
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>java:/JTSEclipseLinkDS</jta-data-source>      <!-- Entities must be specified for EclipseLink weaving -->
    <class>Todo</class>
    <properties>
      <property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.oracle.OraclePlatform"/>
      <!--property name="eclipselink.ddl-generation" value="drop-and-create-tables"/-->
      <property name="eclipselink.target-server" value="org.eclipse.persistence.platform.server.jboss.JBossPlatform"/>
      <!--property name="eclipselink.weaving" value="static"/--><!-- ignored -->
      <property name="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.

  • <property name="eclipselink.target-server" value="org.eclipse.persistence.platform.server.jboss.JBossPlatform"/>

Set target-database

We currently do not have a defined platform for HSQL yet in our list of 10 platforms, you will need to use a different database such as Oracle or MySQL, by setting the target-database and adjusting the jta-data-source if required.

17:12:50,097 INFO  [STDOUT] [EL Info]: 2008.05.05 17:12:50.097--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--Not able to detect platform for vendor name [HSQL Database Engine]. Defaulting to [org.eclipse.persistence.platform.database.DatabasePlatform]. The database dialect used may not match with the database you are using. Please explicitly provide a platform using property eclipselink.target-database.

We will use Oracle 10/11 by defining the following property in persistence.xml.

<property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.oracle.OraclePlatform"/>

Create Database

The eclipselink.ddl-generation property is not used, we will manually create our table by executing the following DDL.

CREATE TABLE TODO (ID NUMBER(19) NOT NULL, DTYPE VARCHAR2(31) NULL, DESCRIPTION VARCHAR2(255) NULL, TITLE VARCHAR2(255) NULL, PRIMARY KEY (ID))

@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 which is not in standard JNDI naming format such as "java:comp/env/ejb/jsfejb3/TodoDao".
InitialContext ctx = new InitialContext();
return (TodoDaoInt) ctx.lookup("jsfejb3/TodoDao/local");

Static Weaving / 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
  • Note: that the ant task references persistence.jar, eclipselink.jar and the persistence 1.0 XSD - you may reference these where they exist on your system.
  • Note: persistence.xml must have the <xml> element for NS validation and namespace references in the <persistence> element.
  • 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

Building

  • 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

Deployment

  • Make sure the JBoss server is running when the ear is copied to the deploy directory or start the server.
17:11:07,633 INFO  [JmxKernelAbstraction] 	jboss.jca:name=DefaultDS,service=DataSourceBinding
17:11:07,635 INFO  [PersistenceUnitDeployment] Starting persistence unit persistence.units:ear=jsfejb3.ear,jar=app.jar,unitName=helloworld
17:11:07,801 INFO  [STDOUT] [EL Warning]: 2008.05.05 17:11:07.784--Thread(Thread[main,5,jboss])--The temporary classLoader for PersistenceLoadProcessor [helloworld] is not available.  Switching classLoader to [org.jboss.mx.loading.UnifiedClassLoader3@18b995c{ url=file:/C:/opt/jboss422/server/default/tmp/deploy/tmp46857jsfejb3.ear ,addedOrder=45}].  Weaving has been disabled for this session. EclipseLink may be unable to get a spec mandated temporary class loader from the server, you may be able to use static weaving as an optional workaround. 
17:11:07,809 INFO  [STDOUT] [EL Finest]: 2008.05.05 17:11:07.802--ServerSession(9262213)--Thread(Thread[main,5,jboss])--Begin predeploying Persistence Unit helloworld; state Initial; factoryCount 0
17:11:07,811 INFO  [STDOUT] [EL Finest]: 2008.05.05 17:11:07.811--ServerSession(9262213)--Thread(Thread[main,5,jboss])--property=eclipselink.weaving; value=true
17:11:07,812 INFO  [STDOUT] [EL Finest]: 2008.05.05 17:11:07.812--ServerSession(9262213)--Thread(Thread[main,5,jboss])--property=eclipselink.orm.throw.exceptions; default value=true
17:11:07,830 INFO  [STDOUT] [EL Finer]: 2008.05.05 17:11:07.827--ServerSession(9262213)--Thread(Thread[main,5,jboss])--Searching for default mapping file in file:/C:/opt/jboss422/server/default/tmp/deploy/tmp46857jsfejb3.ear-contents/app.jar
17:11:07,846 INFO  [STDOUT] [EL Finer]: 2008.05.05 17:11:07.846--ServerSession(9262213)--Thread(Thread[main,5,jboss])--Found a default mapping file at jar:file:/C:/opt/jboss422/server/default/tmp/deploy/tmp46857jsfejb3.ear-contents/app.jar!/META-INF/orm.xml for root URL file:/C:/opt/jboss422/server/default/tmp/deploy/tmp46857jsfejb3.ear-contents/app.jar
17:11:08,600 INFO  [STDOUT] [EL Config]: 2008.05.05 17:11:08.599--ServerSession(9262213)--Thread(Thread[main,5,jboss])--The table name for entity [Todo] is being defaulted to: TODO.
17:11:08,604 INFO  [STDOUT] [EL Config]: 2008.05.05 17:11:08.604--ServerSession(9262213)--Thread(Thread[main,5,jboss])--The discriminator column name for the root inheritance class [class Todo] is being defaulted to: DTYPE.
17:11:08,635 INFO  [STDOUT] [EL Config]: 2008.05.05 17:11:08.635--ServerSession(9262213)--Thread(Thread[main,5,jboss])--The column name for element [public java.lang.String Todo.getDescription()] is being defaulted to: DESCRIPTION.
17:11:08,639 INFO  [STDOUT] [EL Config]: 2008.05.05 17:11:08.639--ServerSession(9262213)--Thread(Thread[main,5,jboss])--The column name for element [public java.lang.String Todo.getTitle()] is being defaulted to: TITLE.
17:11:08,642 INFO  [STDOUT] [EL Finest]: 2008.05.05 17:11:08.642--ServerSession(9262213)--Thread(Thread[main,5,jboss])--End predeploying Persistence Unit helloworld; state Predeployed; factoryCount 1
17:11:08,685 INFO  [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.stateless.StatelessContainer
17:11:08,690 INFO  [JmxKernelAbstraction] installing MBean: jboss.j2ee:ear=jsfejb3.ear,jar=app.jar,name=TodoDao,service=EJB3 with dependencies:
17:11:08,690 INFO  [JmxKernelAbstraction] 	persistence.units:ear=jsfejb3.ear,jar=app.jar,unitName=helloworld
17:11:08,842 INFO  [EJBContainer] STARTED EJB: TodoDao ejbName: TodoDao
17:11:08,864 INFO  [EJB3Deployer] Deployed: file:/C:/opt/jboss422/server/default/tmp/deploy/tmp46857jsfejb3.ear-contents/app.jar
17:11:08,868 INFO  [TomcatDeployer] deploy, ctxPath=/jsfejb3, warUrl=.../tmp/deploy/tmp46857jsfejb3.ear-contents/app-exp.war/
17:11:09,509 INFO  [EARDeployer] Started J2EE application: file:/C:/opt/jboss422/server/default/deploy/jsfejb3.ear

Runtime Query

17:12:50,163 INFO  [STDOUT] [EL Finer]: 2008.05.05 17:12:50.163--UnitOfWork(25258862)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--TX binding to tx mgr, status=STATUS_ACTIVE
17:12:50,164 INFO  [STDOUT] [EL Finest]: 2008.05.05 17:12:50.164--UnitOfWork(25258862)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--Execute query DoesExistQuery()
17:12:50,169 INFO  [STDOUT] [EL Finest]: 2008.05.05 17:12:50.169--UnitOfWork(25258862)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--PERSIST operation called on: Todo@1eacdc4.

Back to the top