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

Difference between revisions of "EclipseLink/Examples/JPA/JBoss Web Tutorial"

(Prerequisites)
m (Outdated)
 
(72 intermediate revisions by 3 users not shown)
Line 1: Line 1:
==EclipseLink JPA Deployed on JBoss using Eclipse WTP==
+
=EclipseLink JPA Deployed on JBoss 6.0.0 M1 using Eclipse 3.5 EE edition=
 +
* <font color="orange">This tutorial needs to be finished and/or expanded - vote for EclipseLink bug# '''[http://bugs.eclipse.org/308477 308477]''' if you would like this work to be fast tracked.</font>
  
If you want to get a small web application running quickly on JBoss use the services provided by the '''Web Tools Project''' pluggin in the '''Eclipse IDE''' to take care of deployment details for you.
+
'''<font color="red">20100217: Updated results of EclipseLink 2.0 on JBoss 6.0.0M1.</font>'''
  
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.
+
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.
  
The DALI project was used to generate Entities from a schema with sequences already populated.
+
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 # [http://bugs.eclipse.org/250477 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===
 
===Development Environment===
'''Hardware:''' Windows Vista SP1, HP Core2Quad, 2.4Ghz, 3Gb Ram
+
'''Hardware:''' Windows 7 64-bit, Core i7 920 Quad Core, 2.7Ghz, 12Gb Ram
  
'''Software:''' [http://phoenix.eclipse.org/packages Eclipse IDE for Java EE 3.4 M5 Ganymede] (Feb 2008) with all 5 packages (DTP 1.6, EMF 2.4, GEF 3.4, WTP 3.0, XSD 2.4), Oracle 11g DB 11.1.0.6.0, Java JDK 1.5.0_11, JBoss 4.2.2
+
'''Software:''' [http://phoenix.eclipse.org/packages 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 Eclipse 3.3 and any DB that EclipseLink supports.
+
This example will run fine with an older version of Eclipse to version 3.4 and any Database that EclipseLink supports.
  
 
===Prerequisites===
 
===Prerequisites===
 
*<font color="green">Install Eclipse</font>
 
*<font color="green">Install Eclipse</font>
**I installed a clean version of Eclipse Ganymede M5 with all of WTP 3.0
+
**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.
 
*<font color="green">Install a Database</font>
 
*<font color="green">Install a Database</font>
**In this example I am using Oracle 11g, the table schemas have already been created manually and all entitity java classes have been generated using the Eclipse DALI tool.
+
**In this example I am using the HSQL database shipped with JBoss - therefore no database installation is required for this tutorial.
  
 
*<font color="green">Install JBoss</font>
 
*<font color="green">Install JBoss</font>
 
**See the following [http://www.jboss.org/jbossas/downloads/ jboss.org Application Server Downloads]
 
**See the following [http://www.jboss.org/jbossas/downloads/ jboss.org Application Server Downloads]
**Here I installed the 4.2.2 version to the following directory.
+
**Here I installed the 6.0.0 M1 Feb 2010 version to the following directory.
<pre>C:\opt\jboss422
+
<pre>C:\opt\jboss600m1
 
Where  
 
Where  
JBOSS_HOME=C:/opt/jboss422
+
JBOSS_HOME=C:/opt/jboss600m1
 
</pre>
 
</pre>
  
===JBoss configuration Changes===
+
===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====
 +
'''<font color="red">Reverify for JBoss 6.0.0M1 - for an Oracle Datasource</font>'''
 +
=====JNDI JTA/non-JTA Server DataSource Setup=====
 
*Copy $JBOSS_HOME\docs\examples\jca\oracle-*ds.xml to $JBOSS_HOME\server\default\deploy
 
*Copy $JBOSS_HOME\docs\examples\jca\oracle-*ds.xml to $JBOSS_HOME\server\default\deploy
*Edit oracle-ds.xml
+
*'''Edit oracle-ds.xml'''
*Enter the following into $JBOSS_HOME\server\default\deploy\oracle-ds.xml
+
*Enter the following into ''$JBOSS_HOME\server\default\deploy\oracle-ds.xml''
<pre>
+
<source lang="xml">
 
+
 
<datasources>
 
<datasources>
 
   <no-tx-datasource>
 
   <no-tx-datasource>
Line 43: Line 75:
 
     <user-name>username</user-name>
 
     <user-name>username</user-name>
 
     <password>password</password>
 
     <password>password</password>
<!--min-pool-size>20</min-pool-size>
 
<max-pool-size>100</max-pool-size>
 
<blocking-timeout-millis>5000</blocking-timeout-millis>
 
<idle-timeout-minutes>1</idle-timeout-minutes-->
 
 
     <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
 
     <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
 
       <metadata>
 
       <metadata>
Line 52: Line 80:
 
       </metadata>
 
       </metadata>
 
   </no-tx-datasource>
 
   </no-tx-datasource>
</pre>
+
</source>
  
*Edit oracle-xa-ds.xml
+
*'''Edit oracle-xa-ds.xml'''
*Enter the following into $JBOSS_HOME\server\default\deploy\oracle-xa-ds.xml
+
*Enter the following into ''$JBOSS_HOME\server\default\deploy\oracle-xa-ds.xml''
<pre>
+
<source lang="xml">
 
<datasources>
 
<datasources>
 
   <xa-datasource>
 
   <xa-datasource>
Line 73: Line 101:
 
       </metadata>
 
       </metadata>
 
   </xa-datasource>
 
   </xa-datasource>
</pre>
+
</source>
*Enter the following into $JBOSS_HOME\server\default\conf\login-config.xml
+
*'''Enter the following into $JBOSS_HOME\server\default\conf\login-config.xml'''
<pre>
+
<source lang="xml">
 
<policy>
 
<policy>
 
<application-policy name = "OracleDbRealm">  
 
<application-policy name = "OracleDbRealm">  
Line 84: Line 112:
 
         <module-option name = "userName">sa</module-option>  
 
         <module-option name = "userName">sa</module-option>  
 
         <module-option name = "password"></module-option>  
 
         <module-option name = "password"></module-option>  
         <module-option name ="managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=OracleDS</module-option>  
+
         <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=OracleDS</module-option>  
 
       </login-module>  
 
       </login-module>  
 
   </authentication>  
 
   </authentication>  
 
</application-policy>
 
</application-policy>
 +
</source>
 +
 +
=====JNDI/JNP Port Conflict Workarounds=====
 +
You may get the following port 1099 conflict if you are also running an Oracle Database.
 +
 +
<pre>
 +
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)
 
</pre>
 
</pre>
 +
 +
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.
 +
<pre>
 +
  TCP    yourpc:1099      yourpc....com:1521  ESTABLISHED
 +
</pre>
 +
 +
<JBOSS_HOME>\server\default\conf\jboss-service.xml|jboss-minimal.xml
 +
 +
<source lang="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>
 +
</source>
 +
 +
* 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.
 +
 +
<pre>
 +
from:
 +
java.naming.provider.url=jnp://localhost:1099
 +
to:
 +
java.naming.provider.url=jnp://localhost:1199
 +
</pre>
 +
 +
====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 [[EclipseLink/Bugs/305331|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
 +
<source lang="java">
 +
 +
 +
@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;
 +
        }
 +
    }
 +
...
 +
}
 +
</source>
 +
 +
=====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======
 +
*The JPA 1.0 specification jar shipped with JBoss EAP is signed.  In order to be able to use '''EclipseLink''' with this specific version of the JBoss server you must override the ejb3-persistence.jar by placing an unsigned version beside the '''eclipselink.jar'' off of the '''server/default/lib''' directory - details are in the [[EclipseLink/Bugs/305331|design page for bug# 305331]]
 +
*http://wiki.eclipse.org/Generating_a_Private_Key_and_a_Keystore
 +
*http://java.sun.com/developer/Books/javaprogramming/JAR/sign/signing.html
 +
 +
===Downloading EclipseLink Libraries===
 +
====Download EclipseLink using HTTP - recommended====
 +
*Proceed to the following URL and download the latest eclipselink.zip which contains everything you need.
 +
**http://www.eclipse.org/eclipselink/downloads/index.php
 +
***'''Click on the "EclipseLink Installer Zip''' link which resolves to http://www.eclipse.org/downloads/download.php?file=/rt/eclipselink/releases/n.n.n/eclipselink-n.n.n.zip
 +
*Expand the zip file and get the following 2 files
 +
**eclipselink-*\eclipselink\jlib\eclipselink.jar
 +
**eclipselink-*\eclipselink\jlib\jpa\javax.persistence_*.jar
 +
 +
====Download EclipseLink using Maven====
 +
See the repository on http://www.eclipse.org/eclipselink/downloads/index.php
 +
 +
====Download EclipseLink using SVN - developers only====
 +
*Get the following ''<font color="blue">eclipselink.jar</font>'' and ''<font color="blue">javax.persistence*.jar</font>'' from http://www.eclipselink.org ready for your EclipseLink shared library.
 +
**The following page details four different ways to either obtain the binary jars or download the source and build them yourself with an anon account.
 +
**http://wiki.eclipse.org/EclipseLink/Source
  
 
===EclipseLink JAR location===
 
===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''
 
The eclipselink.jar should be placed off of ''$JBOSS_HOME/server/default/lib''
 +
  
 
===JDBC JAR location===
 
===JDBC JAR location===
Copy your jdbc driver jar to ''$JBOSS_HOME/server/default/lib''
+
Copy your jdbc driver jar to ''$JBOSS_HOME/common/lib''
  
 
===Create server in Eclipse===
 
===Create server in Eclipse===
 
Open the servers view
 
Open the servers view
'''New | Server | JBoss | JBoss v4.2'''.
+
'''New | Server | JBoss | JBoss v5.0''' - ok for 6.0 use.
  
 
===Create J2EE application===
 
===Create J2EE application===
Line 109: Line 253:
 
Select ''generate deployment descriptor'' if you want to change the context-root
 
Select ''generate deployment descriptor'' if you want to change the context-root
  
*Path changes
+
===UML Data Model===
 +
The following single entity ''Cell'' has a @ManyToMany bidirectional relationship to itself.
 +
 
 +
[[Image: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 [http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.common.ddlgen 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====
 +
*The database schema for this example can be automatically generated using the DDL generation capability of EclipseLink (normally only used by development or for demos).  The following project in SVN can be run as an application managed stand-alone JPA project that has ddl-generation turned on in the persistence.xml.
 +
* http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.common.ddlgen
 +
*Note: DDL Generation is not possible on a container managed entity manager connected to a JTA datasource (if the database uses implicit auto-commits (HSQL does not) - hence the use of a separate project that is server agnostic and sharable by all the [[EclipseLink/Examples/JPA|JPA Web application tutorials]] in this section of the Wiki.
 +
 
 +
====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'''.
 
<pre>
 
<pre>
 
<classpathentry combineaccessrules="false" kind="src" path="/eclipselink.core"/>
 
<classpathentry combineaccessrules="false" kind="src" path="/eclipselink.core"/>
Line 117: Line 282:
 
*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.
 
*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.
  
*''Session Customizer''
+
====@EJB Injection is not available to Servlets - use a JNDI lookup====
**The client will require an implementation of SessionCustomizer that will set the lookupType on the JNDI connector to STRING_LOOKUP instead of Composite.
+
In JBoss the Java EE @EJB annotation has no effect when trying to inject you session bean that holds the entityManager.
 +
<source lang="java">
 +
  @EJB(beanName="ApplicationService") // No effect in JBoss
 +
</source>
  
<pre>
+
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.
 +
 
 +
<source lang="java">
 +
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;
 +
    }
 +
  }
 +
</source>
 +
 
 +
<!--====Session Customizer - deprecated ====
 +
*<font color="red">Note: The session customizer is only required for JBoss 4.2.2</font>
 +
*The client will require an implementation of SessionCustomizer that will set the lookupType on the JNDI connector to STRING_LOOKUP instead of Composite.
 +
*Refer to the following [http://forums.oracle.com/forums/thread.jspa?messageID=3205242&tstart=0 post] for details on this issue with Catalina based containers.
 +
*Refer to the following [http://bugs.eclipse.org/260383 260383 enhancement request] that will make this SessionCustomizer redundant by moving this functionality as standard procedure on the server platform.
 +
 
 +
<source lang="java">
 
import javax.naming.Context;
 
import javax.naming.Context;
 
import javax.naming.InitialContext;
 
import javax.naming.InitialContext;
 
import javax.sql.DataSource;
 
import javax.sql.DataSource;
  
import org.eclipse.persistence.internal.sessions.factories.SessionCustomizer;
+
import org.eclipse.persistence.config.SessionCustomizer;
 +
import org.eclipse.persistence.sessions.server.ServerSession;
 
import org.eclipse.persistence.sessions.JNDIConnector;
 
import org.eclipse.persistence.sessions.JNDIConnector;
 
import org.eclipse.persistence.sessions.Session;
 
import org.eclipse.persistence.sessions.Session;
Line 135: Line 338:
 
  */
 
  */
 
public class JPAEclipseLinkSessionCustomizer implements SessionCustomizer {
 
public class JPAEclipseLinkSessionCustomizer implements SessionCustomizer {
public static final String JNDI_DATASOURCE_NAME = "java:/XAOracleDS";
+
  public static final String JNDI_DATASOURCE_NAME = "java:/DefaultDS";
/**
+
  /**
* Get a dataSource connection and set it on the session with lookupType=STRING_LOOKUP
+
  * Get a dataSource connection and set it on the session with lookupType=STRING_LOOKUP
*/
+
  */
public void customize(Session session) throws Exception {
+
  public void customize(Session session) throws Exception {
JNDIConnector connector = null;
+
    JNDIConnector connector = null;
// Initialize session customizer
+
    // Initialize session customizer
DataSource dataSource = null;
+
    DataSource dataSource = null;
try {
+
      try {
Context context = new InitialContext();
+
        Context context = new InitialContext();
if (null == context) {
+
        if (null == context) {
throw new Exception("Context is null");
+
          throw new Exception("Context is null");
}
+
        }
// Create a new org.jboss.resource.adapter.jdbc.WrapperDataSource
+
        // Create a new org.jboss.resource.adapter.jdbc.WrapperDataSource
connector = new JNDIConnector(context, JNDI_DATASOURCE_NAME);
+
        //connector = new JNDIConnector(context, JNDI_DATASOURCE_NAME);
connector = (JNDIConnector)session.getLogin().getConnector(); // possible CCE
+
        connector = (JNDIConnector)session.getLogin().getConnector(); // possible CCE
// Lookup this new dataSource
+
        // Lookup this new dataSource
dataSource = (DataSource) context.lookup(JNDI_DATASOURCE_NAME);
+
        dataSource = (DataSource) context.lookup(JNDI_DATASOURCE_NAME);
} catch (Exception e) {
+
      } catch (Exception e) {
e.printStackTrace();
+
        e.printStackTrace();
}
+
      }
connector.setDataSource(dataSource);
+
    connector.setDataSource(dataSource);
// Change from Composite to String_Lookup
+
    // Change from COMPOSITE_NAME_LOOKUP to STRING_LOOKUP
connector.setLookupType(JNDIConnector.STRING_LOOKUP);
+
    // Note: if both jta and non-jta elements exist this will only change the first one - and may still result in the COMPOSITE_NAME_LOOKUP being set
// Set the new connection on the session
+
    // Make sure only jta-data-source is in persistence.xml with no non-jta-data-source property set
session.getLogin().setConnector(connector);
+
    connector.setLookupType(JNDIConnector.STRING_LOOKUP);
}
+
 
 +
    // if you are specifying both JTA and non-JTA in your persistence.xml then set both connectors to be safe
 +
    JNDIConnector writeConnector = (JNDIConnector) session.getLogin().getConnector();
 +
    writeConnector.setLookupType(JNDIConnector.STRING_LOOKUP);
 +
    JNDIConnector readConnector = (JNDIConnector) ((DatabaseLogin)((ServerSession)session).getReadConnectionPool().getLogin()).getConnector();
 +
    readConnector.setLookupType(JNDIConnector.STRING_LOOKUP);
 +
 
 +
    // Set the new connection on the session
 +
    session.getLogin().setConnector(connector);
 +
  }
 
}
 
}
</pre>
+
</source>
 +
-->
  
*Persistence.xml
+
====JTA Persistence.xml====
**Put persistence.xml in ''yourProjectWeb\src\META-INF'' with a reference to your SessionCustomizer
+
*JTA is the default ''transaction-type'' when deployed in an EE container.
<pre>
+
*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.
 +
<source lang="xml">
 +
<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>
 +
</source>
 +
 
 +
====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
 +
<source lang="xml">
 
<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 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="unifiedJBoss" transaction-type="JTA">
+
     <persistence-unit name="exampleApplicationManaged" transaction-type="RESOURCE_LOCAL">
      <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
         <jta-data-source>java:/XAOracleDS</jta-data-source>
+
         <non-jta-data-source>java:/DefaultDS</non-jta-data-source>      
         <!-- non-jta-data-source>java:/OracleDS</non-jta-data-source-->
+
         <class>org.eclipse.persistence.example.jpa.server.business.Cell</class>
         <class>org.eclipse.persistence.example.unified.business.StatClass</class>
+
         <class>org.eclipse.persistence.example.jpa.server.business.CellAttribute</class>
..other entities
+
 
         <properties>
 
         <properties>
             <property name="eclipselink.server.platform.class.name" value="org.eclipse.persistence.platform.server.jboss.JBossPlatform"/>
+
             <property name="eclipselink.target-server" value="JBoss"/>
            <property name="eclipselink.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
+
             <property name="eclipselink.target-database" value="HSQL"/>
             <property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.oracle.OraclePlatform"/>           
+
            <property name="eclipselink.weaving" value="false"/>
+
            <property name="eclipselink.session-name" value="default-session"/>           
+
            <property name="eclipselink.session.customizer" value="org.eclipse.persistence.example.unified.integration.JPAEclipseLinkSessionCustomizer"/>
+
 
             <property name="eclipselink.logging.level" value="FINEST"/>
 
             <property name="eclipselink.logging.level" value="FINEST"/>
             <property name="eclipselink.jdbc.read-connections.shared" value="true"/>
+
             <!-- enable SQL parameter binding visibility logging to override ER 329852 -->
            <property name="eclipselink.jdbc.write-connections.min" value="3"/>
+
             <property name="eclipselink.logging.parameters" value="true"/>
            <property name="eclipselink.jdbc.write-connections.max" value="8"/>
+
            <property name="eclipselink.jdbc.read-connections.min" value="3"/>
+
             <property name="eclipselink.jdbc.read-connections.max" value="3"/>
+
            <property name="eclipselink.cache.size.default" value="500"/>
+
            <property name="eclipselink.cache.type.default" value="Full"/>
+
            <property name="eclipselink.orm.throw.exceptions" value="false"/>
+
 
         </properties>       
 
         </properties>       
 
     </persistence-unit>
 
     </persistence-unit>
 
</persistence>
 
</persistence>
 +
</source>
 +
 +
<source lang="java">
 +
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")
 +
..}
 +
</source>
 +
=====non-JTA Output=====
 +
<pre>
 +
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)
 
</pre>
 
</pre>
  
Line 201: Line 488:
  
 
===Publish EAR===
 
===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.
 
*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.
 
*You may also use any combination of running the JBoss server yourself in run or debug mode and using eclipse to publish EAR changes.
*Weaving is turned off when running in SE mode because of [[http://jira.jboss.com/jira/browse/EJBTHREE-572 JIRA-572]]
+
*Dynamic weaving is disabled for now because of [[http://jira.jboss.com/jira/browse/EJBTHREE-572 JIRA-572]] - Use [http://wiki.eclipse.org/EclipseLink/Examples/JPA/Migration/JBoss 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]
 
*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.
 
**In your console window you will see one process both for the server and the deploy target.
 
<pre>
 
<pre>
15:56:57,667 INFO  [Server] Starting JBoss (MX MicroKernel)...
+
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'
15:56:57,668 INFO  [Server] Release ID: JBoss [Trinity] 4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)
+
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
15:57:08,630 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=OracleDS' to JNDI name 'java:OracleDS'
+
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
15:57:08,634 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=TXOracleDS' to JNDI name 'java:TXOracleDS'
+
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
15:57:08,690 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=XAOracleDS' to JNDI name 'java:XAOracleDS'
+
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
15:57:08,806 INFO  [EARDeployer] Init J2EE application: file:/C:/opt/jboss422/server/default/deploy/unifiedEAR.ear
+
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
15:57:08,835 INFO  [TomcatDeployer] deploy, ctxPath=/unified, warUrl=.../tmp/deploy/tmp35385unifiedEAR.ear-contents/unifiedWeb-exp.war/
+
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
15:57:08,926 INFO  [EARDeployer] Started J2EE application: file:/C:/opt/jboss422/server/default/deploy/unifiedEAR.ear
+
15:57:09,026 INFO  [Server] JBoss (MX MicroKernel) [4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)] Started in 11s:350ms
+
 
</pre>
 
</pre>
  
 
===Perform a JPQL query===
 
===Perform a JPQL query===
 
*At this time you can initialize your application in a browser - notice the use of the non-jta datasource
 
*At this time you can initialize your application in a browser - notice the use of the non-jta datasource
** Launch http://127.0.0.1:8080/unified/FrontController?action=init
+
** Launch http://127.0.0.1:8080/enterprise/FrontController?action=demo&rnd=0.31415923
** This url command gets an EM factory via ApplicationService.getInstance().initialize()
+
** This url command gets a container managed persistence context for each call to the SSB ApplicationService - the sequence of operations for '''demo''' is currently
 +
*** Drop/Create database
 +
*** Populate and link 5 entities
 +
*** Query on these entities
 +
*** Display results
 +
<source lang="java">
 +
@Local
 +
@Stateless
 +
public class ApplicationService implements ApplicationServiceLocal  {
 +
@PersistenceContext(unitName="example")
 +
private EntityManager entityManager;
 +
</source>
 +
===Console Output===
 
<pre>
 
<pre>
  emf = Persistence.createEntityManagerFactory(puName);
+
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)
 
</pre>
 
</pre>
*Console Output
+
===Browser Output===
<pre>
+
15:57:23,046 INFO  [STDOUT] [EPS Finest]: 2008.04.14 15:57:23.031--ServerSession(28649942)--Thread(Thread[http-127.0.0.1-8080-2,5,jboss])--Begin predeploying Persistence Unit unifiedJBoss; state Initial; factoryCount 0
+
15:57:23,046 INFO  [STDOUT] [EPS Finest]: 2008.04.14 15:57:23.046--ServerSession(28649942)--Thread(Thread[http-127.0.0.1-8080-2,5,jboss])--property=eclipselink.weaving; value=false
+
15:57:23,244 INFO  [STDOUT] [EPS Config]: 2008.04.14 15:57:23.243--ServerSession(28649942)--Thread(Thread[http-127.0.0.1-8080-2,5,jboss])--The primary key column name for the mapping element [private org.eclipse.persistence.example.unified.business.StatClass org.eclipse.persistence.example.unified.business.StatInheritance.toClass] is being defaulted to: ID.
+
15:57:23,246 INFO  [STDOUT] [EPS Finest]: 2008.04.14 15:57:23.246--ServerSession(28649942)--Thread(Thread[http-127.0.0.1-8080-2,5,jboss])--End predeploying Persistence Unit unifiedJBoss; state Predeployed; factoryCount 0</pre>
+
*Exercise your application in a browser by requesting a JPQL query
+
** Launch <pre>http://127.0.0.1:8080/unified/FrontController?action=query&jpql=select%20object(e)%20from%20StatLabel%20e%20where%20e.id<100</pre>
+
*Console Output
+
<pre>
+
15:57:41,175 INFO  [STDOUT] [EPS Config]: 2008.04.14 15:57:41.175--ServerSession(28649942)--Connection(12593356)--Thread(Thread[http-127.0.0.1-8080-2,5,jboss])--Connected: jdbc:oracle:thin:@localhost:1521:orcl
+
User: username
+
Database: Oracle  Version: Oracle Database 11g Release 11.1.0.0.0 - Production
+
Driver: Oracle JDBC driver  Version: 11.1.0.0.0-Beta5
+
15:57:41,391 INFO  [STDOUT] [EPS Finest]: 2008.04.14 15:57:41.391--UnitOfWork(5316732)--Thread(Thread[http-127.0.0.1-8080-2,5,jboss])--Execute query ReadAllQuery(org.eclipse.persistence.example.unified.business.StatLabel)
+
15:57:41,393 INFO  [STDOUT] [EPS Fine]: 2008.04.14 15:57:41.393--ServerSession(28649942)--Connection(32240107)--Thread(Thread[http-127.0.0.1-8080-2,5,jboss])--SELECT ID, DATE_STAMP FROM STAT_LABEL
+
15:57:41,582 INFO  [STDOUT] [EPS Finest]: 2008.04.14 15:57:41.581--UnitOfWork(5316732)--Thread(Thread[http-127.0.0.1-8080-2,5,jboss])--Register the existing object org.eclipse.persistence.example.unified.business.StatLabel@10ae2bf</pre>
+
**Browser Output
+
 
[[Image:Eclipselink_example_jpa_jboss_web_jpql_action_cap.jpg]]
 
[[Image:Eclipselink_example_jpa_jboss_web_jpql_action_cap.jpg]]
 +
 +
==JPA 2.0 on JBoss 6==
 +
*See the following discussion on the environment and testing results of a JPA 2.0 Java EE application on JBoss 6.
 +
**https://bugs.eclipse.org/bugs/show_bug.cgi?id=250477#c3
 +
**http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg04116.html
 +
===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==
 
==References==
 
*See [[EclipseLink/UserGuide/Developing_JPA_Projects_%28ELUG%29|Developing JPA Projects]] in the EclipseLink User's Guide.
 
*See [[EclipseLink/UserGuide/Developing_JPA_Projects_%28ELUG%29|Developing JPA Projects]] in the EclipseLink User's Guide.
 +
*See [http://wiki.eclipse.org/EclipseLink/Examples/JPA/Migration/JBoss migration procedure on how to run EclipseLink as JPA provider on the JBoss container.]
 +
*[http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg04117.html JBoss 6.0.0 M1 testing discussion]
 +
*20110307 - need to answer the 2 questions posted in http://community.jboss.org/message/590837?tstart=0

Latest revision as of 21:26, 12 June 2013

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