Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EclipseLink/Examples/JPA/JBoss Web Tutorial

EclipseLink JPA Deployed on JBoss 6.0.0 M1 using Eclipse 3.5 EE edition

  • This tutorial needs to be finished and/or expanded - vote for EclipseLink bug# 308477 if you would like this work to be fast tracked.

20100217: Updated results of EclipseLink 2.0 on JBoss 6.0.0M1.

If you want to get a small web application running quickly on JBoss 6 use the services provided by the Web Tools Project project as part of the EE edition of the Eclipse IDE to take care of deployment details for you.

This basic example details how to use Eclipse to run/debug a minimum J2EE web application servlet using EclipseLink JPA as the persistence provider. The goal of this example is to detail the minimum steps needed to run EclipseLink inside JBoss using the Eclipse IDE - at this point no presentation/controller layer such as JSF, Spring or Struts will be used beyond a basic HttpServlet so we can concentrate on the the integration layer JPA setup.

Tutorial Source

The EAR, EJB and WEB Eclipse project source for this EclipseLink JBoss (JPA) tutorial is available online at the following locations. These 3 projects must be imported along with the jpa core eclipselink project or jar.

  • Checkout the following 3 projects together from $trunk/examples.
    • org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEAR
    • org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEJB
    • org.eclipse.persistence.example.jpa.server.jboss.EnterpriseWeb
  • EclipseLink source via SVN committer access

svn+ssh://user@eclipse/svnroot/rt/org.eclipse.persistence/trunk

  • EclipseLink source via SVN anonymous access

svn://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk

The following link will put you at the root of the SVN tree using the online version of subclipse.

http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEAR

http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEJB

http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.jboss.EnterpriseWeb

  • As an alternative if you do not wish to use SVN or the direct html links into SVN - I have attached a version of the EAR including source to enhancement bug # 250477 in versions for JBoss 5.1.0' (JPA 1.0) and JBoss 6.0.0M1 (JPA 2.0) - except that these may not be in sync with the latest SVN repository changes.

Development Environment

Hardware: Windows 7 64-bit, Core i7 920 Quad Core, 2.7Ghz, 12Gb Ram

Software: Eclipse IDE for Java EE 3.5 Galilleo (Nov 2009), Java JDK 1.6.0_17, JBoss 6.0.0M1 including the HSQL database.

This example will run fine with an older version of Eclipse to version 3.4 and any Database that EclipseLink supports.

Prerequisites

  • Install Eclipse
    • I installed a clean version of Eclipse 3.5 Galileo SR1 EE edition with all of WTP 3.0
      • Note: The 64-bit edition currently has issues with EE server plugins - stick to the 32 bit version for now.
    • Eclipse arrives standard with JBoss 5.0 support - you may use the 5.0 version to deploy to 6.0 servers.
  • Install a Database
    • In this example I am using the HSQL database shipped with JBoss - therefore no database installation is required for this tutorial.
C:\opt\jboss600m1
Where 
JBOSS_HOME=C:/opt/jboss600m1

JBoss Server Configuration Changes

  • Launch the JBoss AS Administration console to view the configuration at http://127.0.0.1:8080
    • Username/password is admin/admin
  • You don't need to change anything if you use the default HSQL database - otherwise you must add your own datasource.

HSQL Hypersonic Default Datasource

  • The included DefaultDS datasource resolved to the URL jdbc:hsqldb:C:\opt\jboss600m1\server\default\data\hypersonic\localDB - replace "C:\opt\jboss600m1" with your $JBOSS_INSTALL_DIR.

Custom Datasource Configuration Details

Reverify for JBoss 6.0.0M1 - for an Oracle Datasource

JNDI JTA/non-JTA Server DataSource Setup
  • Copy $JBOSS_HOME\docs\examples\jca\oracle-*ds.xml to $JBOSS_HOME\server\default\deploy
  • Edit oracle-ds.xml
  • Enter the following into $JBOSS_HOME\server\default\deploy\oracle-ds.xml
<datasources>
  <no-tx-datasource>
    <jndi-name>OracleDS</jndi-name>
	<use-java-context>true</use-java-context>
    <connection-url>jdbc:oracle:thin:@localhost:1521:orcl</connection-url>
    <driver-class>oracle.jdbc.OracleDriver</driver-class>
    <user-name>username</user-name>
    <password>password</password>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
      <metadata>
         <type-mapping>Oracle9i</type-mapping>
      </metadata>
  </no-tx-datasource>
  • Edit oracle-xa-ds.xml
  • Enter the following into $JBOSS_HOME\server\default\deploy\oracle-xa-ds.xml
<datasources>
  <xa-datasource>
    <jndi-name>XAOracleDS</jndi-name>
    <use-java-context>true</use-java-context>
    <track-connection-by-tx>true</track-connection-by-tx>
	<isSameRM-override-value>false</isSameRM-override-value>
    <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
    <xa-datasource-property name="URL">jdbc:oracle:thin:@localhost:1521:orcl</xa-datasource-property>
    <xa-datasource-property name="User">username</xa-datasource-property>
    <xa-datasource-property name="Password">password</xa-datasource-property>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
    <no-tx-separate-pools/>
      <metadata>
        <type-mapping>Oracle9i</type-mapping>
      </metadata>
  </xa-datasource>
  • Enter the following into $JBOSS_HOME\server\default\conf\login-config.xml
<policy>
<application-policy name = "OracleDbRealm"> 
   <authentication> 
      <login-module code =  
  "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required"> 
         <module-option name = "principal">sa</module-option> 
         <module-option name = "userName">sa</module-option> 
         <module-option name = "password"></module-option> 
         <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=OracleDS</module-option> 
      </login-module> 
   </authentication> 
</application-policy>
JNDI/JNP Port Conflict Workarounds

You may get the following port 1099 conflict if you are also running an Oracle Database.

14:56:41,597 ERROR [Naming] Could not start on port 1099
java.net.BindException: Address already in use: JVM_Bind at java.net.PlainSocketImpl.socketBind(Native Method)

Try changing the following jboss:service=Naming port to any available port, keep the RmiPort at 1098. Use [netstat -a] to check free ports - in my case 1099 is taken by the 1521 orcl listener.

  TCP    yourpc:1099       yourpc....com:1521  ESTABLISHED

<JBOSS_HOME>\server\default\conf\jboss-service.xml|jboss-minimal.xml

   <mbean code="org.jboss.naming.NamingService"
      name="jboss:service=Naming"
      xmbean-dd="resource:xmdesc/NamingService-xmbean.xml">
...
from
      <attribute name="Port">1199</attribute>
to
      <attribute name="Port">1099</attribute>
  • Eclipse WTP Server configuration

Open the server configuration on the [servers] view and change [Server Properties/JNDI Port] to 1199

  • <app>/JNDI.properties

You will also need to sync this port change in your jndi.properties file (mine is off my web application under src/ just above META-INF.

from:
java.naming.provider.url=jnp://localhost:1099
to:
java.naming.provider.url=jnp://localhost:1199

JBoss 5.0.0 EAP Specific Configurations

JNDI ProxyFactory Issues
  • If you are looking up a @Remote @Stateless session bean that contains an injected EntityManager or EntityManagerFactory - you will need to use a 3 part JNDI lookup of the form

(app_name/bean_name/remote) or (app_name/remote-bean_name/qualified_bean_name) - details are in the design page for bug# 305331

Specifying @Remote @Stateless Session Bean using Defaults
  • The following scenario specifies @Remote on the remote interface and @Stateless on the stateless session bean.
    • This results in the following JNDI name emitted by the server on EAR deploy
@Stateless(name="ApplicationService", mappedName="ApplicationService")
@Remote(ApplicationServiceRemote.class)
public class ApplicationService implements ApplicationServiceRemote  {
	@PersistenceContext(unitName="example", type=PersistenceContextType.TRANSACTION)	
	private EntityManager entityManager;
...
}
 
public class FrontController extends HttpServlet implements Servlet {
    public static final String APPLICATION_SERVICE_JNDI_NAME = "org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEAR/ApplicationService/remote-org.eclipse.persistence.example.jpa.server.business.ApplicationServiceRemote";    
 
    /**
     * Get the SSB ApplicationService bean - using a JNDI context lookup (no EJB injection was used on this servlet)
     * @param viaJNDILookup
     * @return
     */
    public ApplicationServiceRemote getApplicationService(boolean viaJNDILookup) {
        if(null == applicationService && viaJNDILookup) {
            try {
                Hashtable<String, String> env = new Hashtable<String, String>();      
                env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");     
                env.put(Context.PROVIDER_URL, "localhost");      
                env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" );     
                InitialContext ctx = new InitialContext(env);
                System.out.println("FrontController.getApplicationService() JNDI lookup of " + APPLICATION_SERVICE_JNDI_NAME);
                return (ApplicationServiceRemote) ctx.lookup(APPLICATION_SERVICE_JNDI_NAME);            
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException("Exception looking up session bean: ", e);
            }
        } else {
            return applicationService;
        }
    }
...
}
Security
  • To enable the admin console, uncomment the admin:admin user:password entry in the following configuration file on the server.
    • C:\opt\jboss-eap-5.0\jboss-as\server\default\conf\props\jmx-console-users.properties
Signed Jars

Downloading EclipseLink Libraries

Download EclipseLink using HTTP - recommended

Download EclipseLink using Maven

See the repository on http://www.eclipse.org/eclipselink/downloads/index.php

Download EclipseLink using SVN - developers only

EclipseLink JAR location

All Servers

The eclipselink.jar should be placed next to the ejb3-persistence.jar (JBoss 5.1.0) off of $JBOSS_HOME/common/lib

Specific Server

The eclipselink.jar should be placed off of $JBOSS_HOME/server/default/lib


JDBC JAR location

Copy your jdbc driver jar to $JBOSS_HOME/common/lib

Create server in Eclipse

Open the servers view New | Server | JBoss | JBoss v5.0 - ok for 6.0 use.

Create J2EE application

Check out the 3 example projects in the trunk '(TBD) or create your own J2EE Enterprise Application as below. File | new | project | J2EE | Enterprise Application Project Select server, use 5.0 Ear version

Create a new Web and an optional EJB project

Select generate deployment descriptor if you want to change the context-root

UML Data Model

The following single entity Cell has a @ManyToMany bidirectional relationship to itself.

Eclipselink server jee jpa examples datamodel.gif

Tutorial Design

The goal of the tutorial is to demonstrate a quick start end-to-end deployment on a specific application server of an EclipseLink JPA application. To accomplish this...

  • The web framework is a simple servlet so we avoid container specific issues around a JSF implementation.
  • The data model is very simple (@ManyToMany) - as the other tutorials get into more advanced JPA entity concepts and annoations
  • The entityManager is container managed where possible by injection
  • The schema is generated by DDL generation in a separate common application managed SE app for an Oracle DB (because of an implicit auto-commit on create table) or directly when using HSQL.
  • The application context name is standard across servers
  • The datasource is globally defined (by the user) on the server - with the only configuration setting being the jta-data-source element in persistence.xml

DDL/Schema Generation

Reference EclipseLink and JPA - Path changes

  • Either link to the 2 SVN projects below or link to an external eclipselink.jar and javax-persistence.jar.
	<classpathentry combineaccessrules="false" kind="src" path="/eclipselink.core"/>
	<classpathentry combineaccessrules="false" kind="src" path="/eclipselink.jpa"/>
  • After EAR project creation - reference eclipselink.core and eclipselink.jpa or include a reference to eclipselink.jar in your WAR project.
  • If you don't reference the eclipselink.* projects then include a classpath reference to persistence.jar and an Oracle JDBC driver jar for your DB - You will need to put this JDBC driver jar in your JBoss /server/default/lib directory as well.

@EJB Injection is not available to Servlets - use a JNDI lookup

In JBoss the Java EE @EJB annotation has no effect when trying to inject you session bean that holds the entityManager.

  @EJB(beanName="ApplicationService") // No effect in JBoss

Use the following JNDI name and lookup in your Servlet where org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEAR is the name of your EAR project and ApplicationService is the name of your @Local @Stateless session bean.

public class FrontController extends HttpServlet implements Servlet {
public static final String APPLICATION_SERVICE_JNDI_NAME = "org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEAR/ApplicationService/local";
  @EJB(beanName="ApplicationService") // No effect in JBoss
  public ApplicationServiceLocal applicationService;
 
 
  public ApplicationServiceLocal getApplicationService() {
    if(null == applicationService) {
      try {
        Hashtable env = new Hashtable();      
        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");     
        env.put(Context.PROVIDER_URL, "localhost");      
        env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" );     
        InitialContext ctx = new InitialContext(env);
        return (ApplicationServiceLocal) ctx.lookup(APPLICATION_SERVICE_JNDI_NAME);            
      } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Datasource not available - lookukp failed: ", e);
      }
    } else {
      return applicationService;
    }
  }


JTA Persistence.xml

  • JTA is the default transaction-type when deployed in an EE container.
  • JTA : Put persistence.xml beside your JPA entities in yourProjectEJB/ejbModule/META-INF
  • Note: Your <jta-data-source> or <non-jta-data-source> element in persistence.xml must match the JNDI Name: on the server admin page.
<persistence version="2.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_2_0.xsd">
    <persistence-unit name="example" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>java:/DefaultDS</jta-data-source>        
        <class>org.eclipse.persistence.example.jpa.server.business.Cell</class>
        <class>org.eclipse.persistence.example.jpa.server.business.CellAttribute</class>
        <shared-cache-mode>NONE</shared-cache-mode> <!-- test design time and deployment of JPA 2.0 -->
        <properties>
            <!-- Application managed datasource -->
            <property name="eclipselink.target-server" value="JBoss"/>
            <property name="eclipselink.target-database" value="HSQL"/>
            <!-- remove for production -->
            <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
            <property name="eclipselink.ddl-generation.output-mode" value="database"/>
            <property name="eclipselink.logging.level" value="FINEST"/>
            <!-- enable SQL parameter binding visibility logging to override ER 329852 -->
            <property name="eclipselink.logging.parameters" value="true"/>
        </properties>       
    </persistence-unit>
</persistence>

non-JTA Persistence.xml

  • The following RESOURCE_LOCAL non-jta-data-source requires that we use a non-transactional stateful session bean instead of a standard @Stateless bean
<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="exampleApplicationManaged" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <non-jta-data-source>java:/DefaultDS</non-jta-data-source>        
        <class>org.eclipse.persistence.example.jpa.server.business.Cell</class>
        <class>org.eclipse.persistence.example.jpa.server.business.CellAttribute</class>
        <properties>
            <property name="eclipselink.target-server" value="JBoss"/>
            <property name="eclipselink.target-database" value="HSQL"/>
            <property name="eclipselink.logging.level" value="FINEST"/>
            <!-- enable SQL parameter binding visibility logging to override ER 329852 -->
            <property name="eclipselink.logging.parameters" value="true"/>
        </properties>       
    </persistence-unit>
</persistence>
public class FrontController extends HttpServlet implements Servlet {
    public static final String APPLICATION_SERVICE_JNDI_NAME = "org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEAR/ApplicationService/remote-org.eclipse.persistence.example.jpa.server.business.ApplicationServiceRemote";      private ApplicationServiceRemote applicationService;
...}
 
@Stateful(name="ApplicationService", mappedName="ApplicationService")
@Remote(ApplicationServiceRemote.class)
public class ApplicationService implements ApplicationServiceRemote  {
    private EntityManager entityManager;
    @PersistenceUnit(unitName="exampleApplicationManaged")
..}
non-JTA Output
14:34:34,944 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=DefaultDS' to JNDI name 'java:DefaultDS'

14:34:38,396 INFO  [JBossASKernel] installing bean: jboss.j2ee:ear=org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEAR.ear,jar=org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEJB.jar,name=ApplicationService,service=EJB3
14:34:38,396 INFO  [JBossASKernel]   with dependencies:
14:34:38,396 INFO  [JBossASKernel]   and demands:
14:34:38,396 INFO  [JBossASKernel] 	jboss.ejb:service=EJBTimerService
14:34:38,396 INFO  [JBossASKernel] 	persistence.unit:unitName=org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEAR.ear/org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEJB.jar#exampleApplicationManaged

14:34:39,497 INFO  [EJBContainer] STARTED EJB: org.eclipse.persistence.example.jpa.server.business.ApplicationService ejbName: ApplicationService

14:34:44,058 INFO  [STDOUT] [EL Finest]: 2010-06-24 14:34:44.058--ServerSession(29865054)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--Begin deploying Persistence Unit exampleApplicationManaged; session vfszip:/C:/opt/jboss-eap-5.0b/jboss-as/server/default/deploy/org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEAR.ear/org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEJB.jar/_exampleApplicationManaged; state Predeployed; factoryCount 1
14:34:44,598 INFO  [STDOUT] [EL Config]: 2010-06-24 14:34:44.598--ServerSession(29865054)--Connection(13945008)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--connecting(DatabaseLogin(
	platform=>HSQLPlatform
	user name=> ""
	connector=>JNDIConnector datasource name=>null
))
14:34:44,618 INFO  [STDOUT] [EL Config]: 2010-06-24 14:34:44.618--ServerSession(29865054)--Connection(29608557)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--Connected: jdbc:hsqldb:C:\opt\jboss-eap-5.0b\jboss-as\server\default\data\hypersonic\localDB
	User: SA
	Database: HSQL Database Engine  Version: 1.8.0
	Driver: HSQL Database Engine Driver  Version: 1.8.0
14:34:44,618 INFO  [STDOUT] [EL Config]: 2010-06-24 14:34:44.618--ServerSession(29865054)--Connection(11021090)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--connecting(DatabaseLogin(
	platform=>HSQLPlatform
	user name=> ""
	connector=>JNDIConnector datasource name=>null
))
14:34:44,618 INFO  [STDOUT] [EL Config]: 2010-06-24 14:34:44.618--ServerSession(29865054)--Connection(11002691)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--Connected: jdbc:hsqldb:C:\opt\jboss-eap-5.0b\jboss-as\server\default\data\hypersonic\localDB
	User: SA
	Database: HSQL Database Engine  Version: 1.8.0
	Driver: HSQL Database Engine Driver  Version: 1.8.0
14:34:44,628 INFO  [STDOUT] [EL Finest]: 2010-06-24 14:34:44.628--ServerSession(29865054)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--sequencing connected, state is Preallocation_NoTransaction_State
14:34:44,628 INFO  [STDOUT] [EL Finest]: 2010-06-24 14:34:44.628--ServerSession(29865054)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--sequence EL_CELL_SEQ: preallocation size 25
14:34:44,678 INFO  [STDOUT] [EL Info]: 2010-06-24 14:34:44.678--ServerSession(29865054)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--vfszip:/C:/opt/jboss-eap-5.0b/jboss-as/server/default/deploy/org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEAR.ear/org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEJB.jar/_exampleApplicationManaged login successful
14:34:44,728 INFO  [STDOUT] [EL Finest]: 2010-06-24 14:34:44.728--ServerSession(29865054)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--End deploying Persistence Unit exampleApplicationManaged; session vfszip:/C:/opt/jboss-eap-5.0b/jboss-as/server/default/deploy/org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEAR.ear/org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEJB.jar/_exampleApplicationManaged; state Deployed; factoryCount 1

14:34:44,938 INFO  [STDOUT] [EL Finest]: 2010-06-24 14:34:44.938--UnitOfWork(19973008)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--Execute query ReadAllQuery(referenceClass=Cell sql="SELECT ID, STATE, TSEQ, ACELLATTRIBUTE_ID, RIGHT_ID FROM EL_CELL")
14:34:44,948 INFO  [STDOUT] [EL Finest]: 2010-06-24 14:34:44.948--ServerSession(29865054)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--reconnecting to external connection pool
14:34:44,948 INFO  [STDOUT] [EL Fine]: 2010-06-24 14:34:44.948--ServerSession(29865054)--Connection(23896594)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--SELECT ID, STATE, TSEQ, ACELLATTRIBUTE_ID, RIGHT_ID FROM EL_CELL
14:34:44,980 INFO  [STDOUT] [EL Finest]: 2010-06-24 14:34:44.98--ServerSession(29865054)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--Execute query ReadAllQuery(name="references" referenceClass=Cell sql="SELECT t1.ID, t1.STATE, t1.TSEQ, t1.ACELLATTRIBUTE_ID, t1.RIGHT_ID FROM EL_CELL_EL_CELL t0, EL_CELL t1 WHERE ((t0.peers_ID = ?) AND (t1.ID = t0.references_ID))")
14:34:44,980 INFO  [STDOUT] [EL Finest]: 2010-06-24 14:34:44.98--ServerSession(29865054)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--reconnecting to external connection pool
14:34:44,980 INFO  [STDOUT] [EL Fine]: 2010-06-24 14:34:44.98--ServerSession(29865054)--Connection(1204646)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--SELECT t1.ID, t1.STATE, t1.TSEQ, t1.ACELLATTRIBUTE_ID, t1.RIGHT_ID FROM EL_CELL_EL_CELL t0, EL_CELL t1 WHERE ((t0.peers_ID = ?) AND (t1.ID = t0.references_ID))
	bind => [1]
14:34:45,000 INFO  [STDOUT] [EL Finest]: 2010-06-24 14:34:45.0--UnitOfWork(19973008)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--Register the existing object org.eclipse.persistence.example.jpa.server.business.Cell@11437483( id: 2 state: null left: null right: null parent: HashSet@29739708 references: HashSet@29739708)

Start Server

  • Steps: Select the EAR and [Run on Server].
  • The first "Run on Server" may not start the server, in this case you "Start Server" and then "Run on Server".

Publish EAR

  • Publishing to JBoss 6 is very simple, once the server is setup you can just drop/remove an EAR in the deploy directory to deploy/undeploy an application. Or use Eclipse to debug via the 5005 port if the server is managed through WTP.
  • Eclipse WTP will take care of copying the EAR file to the live deploy directory when you either [re-publish] or modify any files while the server is running.
  • You may also use any combination of running the JBoss server yourself in run or debug mode and using eclipse to publish EAR changes.
  • Dynamic weaving is disabled for now because of [JIRA-572] - Use static weaving workaround before deploying if required. This affects change tracking and lazy loading only.
  • Depending on your application you will see the following after running [start server]
    • In your console window you will see one process both for the server and the deploy target.
2010-02-17 22:17:26,316 INFO  [org.jboss.resource.connectionmanager.ConnectionFactoryBindingService] (Thread-2) Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=DefaultDS' to JNDI name 'java:DefaultDS'
2010-02-17 22:17:33,217 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (Thread-2) Created KernelDeployment for: org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEJB.jar
2010-02-17 22:17:33,217 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (Thread-2) installing bean: jboss.j2ee:ear=org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEAR.ear,jar=org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEJB.jar,name=ApplicationService,service=EJB3
2010-02-17 22:17:35,637 INFO  [STDOUT] (Thread-2) [EL Finest]: 2010-02-17 22:17:35.637--ServerSession(7054061)--Thread(Thread[Thread-2,5,jboss])--End predeploying Persistence Unit example; session vfszip:/C:/opt/jboss600m1/server/default/deploy/org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEAR.ear/org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEJB.jar/_example; state Predeployed; factoryCount 1
2010-02-17 22:17:35,730 INFO  [org.jboss.ejb3.session.SessionSpecContainer] (Thread-2) Starting jboss.j2ee:ear=org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEAR.ear,jar=org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEJB.jar,name=ApplicationService,service=EJB3
2010-02-17 22:17:35,746 INFO  [org.jboss.ejb3.EJBContainer] (Thread-2) STARTED EJB: org.eclipse.persistence.example.jpa.server.business.ApplicationService ejbName: ApplicationService
2010-02-17 22:17:36,199 INFO  [org.jboss.bootstrap.impl.base.server.AbstractServer] (Thread-2) JBossAS [6.0.0.M1 (build: SVNTag=JBoss_6_0_0_M1 date=200912040958)] Started in 43s:528ms

Perform a JPQL query

  • At this time you can initialize your application in a browser - notice the use of the non-jta datasource
@Local
@Stateless
public class ApplicationService implements ApplicationServiceLocal  {
	@PersistenceContext(unitName="example")
	private EntityManager entityManager;

Console Output

2010-02-17 22:23:14,955 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Info]: 2010-02-17 22:23:14.955--ServerSession(7054061)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--EclipseLink, version: Eclipse Persistence Services - 2.1.0.qualifier
2010-02-17 22:23:14,986 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: 2010-02-17 22:23:14.986--ServerSession(7054061)--Connection(18421505)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--Connected: jdbc:hsqldb:C:\opt\jboss600m1\server\default\data\hypersonic\localDB
	User: SA
	Database: HSQL Database Engine  Version: 1.8.0
	Driver: HSQL Database Engine Driver  Version: 1.8.0
...
2010-02-17 22:23:15,204 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Fine]: 2010-02-17 22:23:15.204--ServerSession(7054061)--Connection(32007964)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--DROP TABLE EL_CELL
2010-02-17 22:23:15,204 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Finest]: 2010-02-17 22:23:15.204--ServerSession(7054061)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--Execute query DataModifyQuery(sql="CREATE TABLE EL_CELL (ID BIGINT NOT NULL, STATE VARCHAR(255), TSEQ VARCHAR(255), RIGHT_ID BIGINT, ACELLATTRIBUTE_ID INTEGER, PRIMARY KEY (ID))")
2010-02-17 22:23:15,204 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Finest]: 2010-02-17 22:23:15.204--ServerSession(7054061)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--reconnecting to external connection pool
2010-02-17 22:23:15,204 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Fine]: 2010-02-17 22:23:15.204--ServerSession(7054061)--Connection(12574077)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--CREATE TABLE EL_CELL (ID BIGINT NOT NULL, STATE VARCHAR(255), TSEQ VARCHAR(255), RIGHT_ID BIGINT, ACELLATTRIBUTE_ID INTEGER, PRIMARY KEY (ID))
...
2010-02-17 22:23:16,282 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Finest]: 2010-02-17 22:23:16.282--UnitOfWork(1394419)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--Execute query InsertObjectQuery(org.eclipse.persistence.example.jpa.server.business.Cell@31677102( id: 2 state: null left: null right: null parent: HashSet@54753502 references: HashSet@54753502))
2010-02-17 22:23:16,297 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Finest]: 2010-02-17 22:23:16.297--ClientSession(15006870)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--reconnecting to external connection pool
2010-02-17 22:23:16,297 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Fine]: 2010-02-17 22:23:16.297--ClientSession(15006870)--Connection(15718095)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--INSERT INTO EL_CELL (ID, STATE, TSEQ, RIGHT_ID, ACELLATTRIBUTE_ID) VALUES (?, ?, ?, ?, ?)
	bind => [2, null, null, null, null]
...
2010-02-17 22:23:16,329 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Finer]: 2010-02-17 22:23:16.329--UnitOfWork(1394419)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--TX afterCompletion callback, status=COMMITTED
2010-02-17 22:23:16,329 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Finer]: 2010-02-17 22:23:16.329--UnitOfWork(1394419)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--end unit of work commit
2010-02-17 22:23:16,375 INFO  [STDOUT] (http-127.0.0.1-8080-1) FrontController.getApplicationService() JNDI lookup of org.eclipse.persistence.example.jpa.server.jboss.EnterpriseEAR/ApplicationService/local
2010-02-17 22:23:16,734 INFO  [STDOUT] (http-127.0.0.1-8080-1) _Test: JPA 2.0 Metamodel: MetamodelImpl@31657000 [ 5 Types: , 2 ManagedTypes: , 2 EntityTypes: , 0 MappedSuperclassTypes: , 0 EmbeddableTypes: ]
...
2010-02-17 22:23:16,734 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Finest]: 2010-02-17 22:23:16.734--UnitOfWork(20126243)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--Execute query ReadAllQuery(referenceClass=Cell sql="SELECT ID, STATE, TSEQ, RIGHT_ID, ACELLATTRIBUTE_ID FROM EL_CELL")

...
2010-02-17 22:23:16,765 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Finest]: 2010-02-17 22:23:16.765--UnitOfWork(20126243)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--Execute query ReadObjectQuery(name="left" referenceClass=Cell sql="SELECT ID, STATE, TSEQ, RIGHT_ID, ACELLATTRIBUTE_ID FROM EL_CELL WHERE (RIGHT_ID = ?)")
2010-02-17 22:23:16,765 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Finest]: 2010-02-17 22:23:16.765--ServerSession(7054061)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--reconnecting to external connection pool
2010-02-17 22:23:16,765 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Fine]: 2010-02-17 22:23:16.765--ServerSession(7054061)--Connection(4514793)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--SELECT ID, STATE, TSEQ, RIGHT_ID, ACELLATTRIBUTE_ID FROM EL_CELL WHERE (RIGHT_ID = ?)
	bind => [1]
2010-02-17 22:23:16,765 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Finer]: 2010-02-17 22:23:16.765--UnitOfWork(20126243)--Thread(Thread[http-127.0.0.1-8080-1,5,jboss])--TX beforeCompletion callback, status=STATUS_ACTIVE
2010-02-17 22:23:16,765 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Example]: enterprise: Object: org.eclipse.persistence.example.jpa.server.business.Cell@30810284( id: 1 state: null left: null right: null parent: HashSet@13182744 references: HashSet@13182744)

Browser Output

Eclipselink example jpa jboss web jpql action cap.jpg

JPA 2.0 on JBoss 6

Configuration

  • EAR
    • ejb-jar
      • persistence.xml - JTA TX datasource using the default Hypersonic database
      • @Stateless @Local session bean with injected @PersistenceContext (default TRANSACTION type) container managed entityManager
      • 2 entities with @OneToOne and @ManyToMany orm relationships
    • web.war
      • Servlet with (no @EJB or @Resource injection) - uses recommended org.jnp context lookup for the SSB above containing the CM EM

JBoss 5.1.0

  • add the EclipseLink 2.0 jar to
    • C:\opt\jboss510\common\lib\eclipselink.jar
    • (optionally override ejb3-persistence.jar with javax.persistence_2.0.jar)

JBoss 6.0.0M1

  • C:\opt\jboss600m1\common\lib\eclipselink.jar
  • <no javax.persistence_2.0.jar override required>

History

  • 20090329 - last edit for JBoss 4.2
  • 20091115 - Updating site for JBoss 5.1.0
    • Notes (to be integrated into main page)
      • Disable JBossPlatform public JPAClassLoaderHolder getNewTempClassLoader(PersistenceUnitInfo puInfo) workaround
      • Increase server start timeout past 50 sec (60+) for a slower T4200 2.2GHz Core2 Win7-64 machine
  • 20100217 - Update for JBoss 6.0.0M1

References

Back to the top