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.
EclipseLink/Examples/JPA/OC4J Web Tutorial
Contents
- 1 EclipseLink JPA Deployed on OC4J using Eclipse WTP
- 1.1 Quick Start Notes
- 1.2 Document History
- 1.3 Tutorial Source
- 1.4 Development Environment
- 1.5 Prerequisites
- 1.6 OC4J configuration Changes
- 1.7 EclipseLink JAR location
- 1.7.1 Downloading EclipseLink Libraries
- 1.7.2 eclipselink.jar on the Server or EAR?
- 1.7.3 Option 1: Add a versioned new EclipseLink shared-library module - recommended
- 1.7.4 Option 2: Modify an existing shared-library - not recommended
- 1.7.5 Option 3: eclipselink.jar in applib - not recommended
- 1.7.6 Option 4: eclipselink.jar specified at startup - not recommended
- 1.7.7 Option 5: JPA 2.0 EclipseLink library using new Shared Library - Recommended
- 1.7.8 Linking source to binaries and debugging EclipseLink - optional step
- 1.8 JDBC JAR location
- 1.9 Create server in Eclipse
- 1.10 Create J2EE application
- 1.11 Persistence.xml
- 1.12 Start Server
- 1.13 Publish EAR
- 1.14 Perform a JPQL query
- 1.15 Troubleshooting
- 1.16 References
EclipseLink JPA Deployed on OC4J using Eclipse WTP
Note: OC4J 10.1.3.5 is a JEE 1.4 compatible application server with addition EJB 3.0 and JPA 1.0 support.
Quick Start Notes
- The following summary lists the essential changes required (beyond what is shipped out of the box) to get running up quickly for advanced users.
- 1) Add a new org.eclipse.persistence shared-library containing the 2 jars required to run EclipseLink JPA
- 2) Either create a new 10.1.3 server in Eclipse and deploy your EAR there, or deploy your EAR manually via the EM console.
Document History
Date | Author | Version Description & Notes |
---|---|---|
20080414 | Michael O'Brien | Initial version covering Oracle OC4J 10.1.3.4 and 11.1.1.0 |
20090217 | Michael O'Brien | Updated for version 10.1.3.5 - completed 20090226 |
If you want to get a small web application running quickly on OC4J use the services provided by the Web Tools Project plugin in 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 OC4J 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.
The DALI project was used to generate Entities from a schema with sequences already populated.
Tutorial Source
The EAR, EJB and WEB Eclipse project source for this EclipseLink OC4J tutorial will be available online at the following locations. These 3 projects must be imported along with the jpa core eclipselink project.
See: http://wiki.eclipse.org/EclipseLink/Source
- Checkout the following 3 projects together from $trunk/examples.
See http://bugs.eclipse.org/250475
And the DDL generation J2SE JPA application used to populate the database schema.
Development Environment
Hardware: Windows Vista SP1, Core2Duo E8400 45nm, 3.0Ghz, 3Gb Ram
Software: Eclipse IDE for Java EE 3.4 Ganymede (SR1 Oct 2008), Oracle 11g DB 11.1.0.6.0, Java JDK 1.6.0_07, OC4J 10.1.3.5.0 20090709
This example will run fine with any DB that EclipseLink supports via the eclipselink.target-database tag.
Prerequisites
Install Eclipse
- I installed a clean version of Eclipse Ganymede EE SR1 Version: 3.4.1 Build id: M20080911-1700 with all of WTP 3.0
Install a Database
- In this example I am using Oracle 11g, the table schemas have already been created either manually or using DDL generation in the SE example. All entity java classes have been generated using the Eclipse DALI tool.
Install OC4J 10.1.3.X
- See http://www.oracle.com/technology/software/products/ias/htdocs/utilsoft.html
- Here I installed OC4J 10.1.3.5 Standalone version to the following directory.
C:\opt\oc4j1014 Where OC4J_ROOT=C:/opt/oc4j1014/j2ee/home ORACLE_HOME=c:/opt/oc4j1014
Verify OC4J Installation
- Before we add EclipseLink and our own JTA datasource to OC4J, lets verify the installation outside of eclipse before adding the server to the IDE.
Start OC4J the first time Outside Eclipse
- If this is the first time you are running your OC4J server, you will want to login from a CMD prompt - to set the admin password.
- The ORACLE_HOME environment variable should also be set to a truncated OC4J_ROOT or c:\opt\oc4j1014
- Launch server via CMD prompt - and create your admin password.
C:\opt\oc4j1014\bin>oc4j -start Starting OC4J from c:\opt\oc4j1014\j2ee\home ... 2009-02-18 14:15:03.406 NOTIFICATION Auto-unpacking C:\opt\oc4j1014\j2ee\home\applications\dms.war... ... Feb 18, 2009 2:15:09 PM com.evermind.server.XMLApplicationServerConfig randomizeJtaAdminPassword INFO: Updating JtaAdmin account 09/02/18 14:15:09 Set OC4J administrator's password (password text will not be displayed as it is entered) Enter password: Confirm password: The password for OC4J administrator "oc4jadmin" has been set. 09/02/18 14:15:21 The OC4J administrator "oc4jadmin" account is activated. 09/02/18 14:15:27 Oracle Containers for J2EE 10g (10.1.3.5.0) initialized
Verify OC4J HTTP 8888 and ORMI 23791 ports are running
C:\opt\oc4j1014\bin>netstat -a TCP 0.0.0.0:8888 mfobrien-PC3:0 LISTENING TCP 0.0.0.0:23791 mfobrien-PC3:0 LISTENING
- Launch the admin page.
Verify that OC4J shutdown works fine
- Open a separate cmd prompt and shutdown the server.
C:\opt\oc4j1014\bin>oc4j -shutdown -port 23791 -password password Shutdown OC4J instance... C:\opt\oc4j1014\bin>
- Observe that oc4j is shutdown in the original CMD prompt.
09/02/18 14:38:22 Shutting down... C:\opt\oc4j1014\bin>
OC4J configuration Changes
- OC4J ships with a default JTA datasource called OracleDS that points to an Oracle DB install on the same machine.
- Use or Edit the OC4J config in $OC4J_ROOT/config/data-sources.xml and enter the following DataSource definition for JTA and non-JTA sources and refering to it in the managed-data-source. The only thing you may need to change is the IP address 127.0.0.1 if your database server is on another machine, the user, password and schema name orcl.
<managed-data-source name="OracleDS" connection-pool-name="local oracle11g" jndi-name="jdbc/OracleDS"/> <connection-pool name="local oracle11g"> <connection-factory factory-class="oracle.jdbc.pool.OracleDataSource" user="user" password="password" url="jdbc:oracle:thin:@//127.0.0.1:1521/orcl"> </connection-factory> </connection-pool>
Note: If you modify a JDBC datasource using the EM UI - the data-sources.xml will be completely regenerated and any commented elements will be overwritten - if you would like to keep them then edit data-sources.xml manually.
EclipseLink JAR location
The OC4J 10.1.3 release does not ship with the EclipseLink JPA provider - you will need to modify or create a shared library to pick up the jars.
There are 2 jar files required to run the EclipseLink provider on OC4J - eclipselink.jar and a version of the JPA 1.0 specification jar - currently javax.persistence_*.jar
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
- http://www.eclipse.org/eclipselink/downloads/index.php
- 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 eclipselink.jar and javax.persistence*.jar 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 on the Server or EAR?
- It is not recommended that you distribute eclipselink.jar with your EAR application in a production environment.
- Why? One reason is that an application deployed EclipseLink jar will be lower on the server ClassLoader tree and will not be available to other modules or applications higher up due to hierarchical visibility constraints. However, there may be occasions during development or staging that you will want to run a local copy or different version than the one loaded from the modules directory - I have not tested this scenario yet, a test of the 3 use cases will be required.
- In this OC4J configuration step we will create a new versioned shared-library for EclipseLink and reference any dependent jars in the xml config files.
- Note: this option is still being tested - use Option 1 above for now.
- Create a new org.eclipse.persistence directory off of $OC4J_ROOT/shared-lib with a subdirectory n.n.n for this specific version - the jars will be placed and referenced here.
C:\opt\oc4j101n\j2ee\home\shared-lib\org.eclipse.persistence\n.n.n\
- Edit $OC4J_ROOT/config/server.xml and add the following shared-library element above the existing oracle.persistence.
- Note: 20100712 changed and verified path="*.jar" below to "path="../shared-lib/org.eclipse.persistence/2.1.0/*.jar"
<shared-library name="org.eclipse.persistence" version="2.1.0" library-compatible="true"> <!-- jars are referenced relative to the name/version directory --> <code-source path="../shared-lib/org.eclipse.persistence/2.1.0/eclipselink.jar"/> <code-source path="../shared-lib/org.eclipse.persistence/2.1.0/javax.persistence/2.0.1.v201006031150.jar"/> <import-shared-library name="oracle.jdbc"/> </shared-library>
Note: Notice that we are picking up the shipped oracle.jdbc library in the last line - we don't need to redeploy this jar to the server.
- Add the following import-shared-library element above the existing two shared libraries oracle.persistence and oracle.toplink in $OC4J_ROOT/config/system-application.xml around line 30.
<imported-shared-libraries> <!-- new EclipseLink shared library --> <import-shared-library name="org.eclipse.persistence"/> <!-- existing shipped out-of-the-box libraries --> <import-shared-library name="oracle.toplink"/> <import-shared-library name="oracle.persistence"/>
- Restart or start the server to pickup changes.
- You should see the following to start
[EL Finest]: 2010-07-12 14:48:34.285--ServerSession(19397123)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--Begin deploying Persistence Unit example; session file:/C:/opt/oc4j10135/j2ee/home/applications/org.eclipse.persistence.example.jpa.server.oc4j.enterpriseEAR/ org.eclipse.persistence.example.jpa.server.oc4j.enterpriseEJB.jar_example; state Predeployed; factoryCount 1
- The following step replaces the default TopLink Essentials JPA library with the EclipseLink provider - this is the fastest but not recommended configuration modification. It would be better to create a new EclipseLink shared library.
- As of OC4J Server 10.1.3+ the TopLink Essentials library is shipped in the following location on the server - we will replace the jar references to this library with EclipseLink versions.
- $OC4J_ROOT/toplink/jlib/toplink.jar
- Create a new eclipselink directory off of $OC4J_ROOT at the same level as the existing toplink directory.
- $OC4J_ROOT/eclipselink/eclipselink.jar
- $OC4J_ROOT/eclipselink/javax.persistence_*.jar
Modify server.xml
- Edit $OC4J_ROOT/config/server.xml and edit the following shared-library "code-source" elements in oracle.persistence.
- The following existing markup is modified from TopLink Essentials
<shared-library name="oracle.persistence" version="1.0" library-compatible="true"> <code-source path="../../../toplink/jlib/toplink-essentials.jar"/> <import-shared-library name="oracle.jdbc"/> </shared-library>
- to org.eclipse.persistence
<shared-library name="oracle.persistence" version="1.0" library-compatible="true"> <code-source path="../../../eclipselink/eclipselink.jar"/> <code-source path="../../../eclipselink/javax.persistence_*.jar"/> <import-shared-library name="oracle.jdbc"/> </shared-library>
Note: Notice that we are picking up the shipped oracle.jdbc library in the last line - we don't need to redeploy this jar to the server.
- Verify that oracle.persistence exists in $OC4J_ROOT/config/system-application.xml around line 30.
<imported-shared-libraries> <!-- existing shipped out-of-the-box libraries - we are replacing jars in oracle.persistence --> <import-shared-library name="oracle.toplink"/> <import-shared-library name="oracle.persistence"/>
- There is also an empty directory for toplink that can be ignored.
$OC4J_ROOT\applications\ascontrol\ascontrol\ias\oc4j\toplink
Option 3: eclipselink.jar in applib - not recommended
The approach will work fine for most configurations however placing eclipselink.jar in the applib directory will put it lower in the classpath than creating a shared-library in option 1.
The eclipselink.jar may be placed as noted by config/server.xml in the directory $OC4J_ROOT/applib or in my case C:\opt\oc4j1014\j2ee\home\applib
<!-- Global application libraries --> <shared-library name="global.libraries" version="1.0" library-compatible="true"> <code-source path="../applib"/> </shared-library>
This approach will not allow you to easily version different distributions of EclipseLink - like you are able to using a shared-library via the version tag, in option 1.
However if you go the route of using the applib directory then you will need to also put a version of javax.persistence.*.jar as well as a version of the jdbc jar your database requires - in my case orai18n.jar or ojdbc14.jar.
Otherwise you will see the following missing JDBC jar CNFE on your first entityManager interaction with the database.
09/02/26 13:23:16 javax.ejb.EJBException: java.lang.NoClassDefFoundError: org/eclipse/persistence/internal/platform/database/oracle/TIMESTAMPTypes 09/02/26 13:23:16 at com.evermind.server.ejb.EJBUtils.getLocalUserException(EJBUtils.java:337)
Option 4: eclipselink.jar specified at startup - not recommended
TBD. If you want to reference eclipselink.jar outside of the OC4J install then you must modify the startup script that was generated for your domain.
see $OC4J_ROOT/bin/oc4j.cmd:183 appended to the following line.
"%JAVA_HOME%\bin\java" %JVMARGS% -jar "%OC4J_JAR%" %CMDARGS%
- See request at the following forum post.
- This is the same as option 1 except for the fact that using JPA 2.0 javax.persistence functionality (JPA 2.0 on a JPA 1.0 compliant server) will not work with container managed - injected persistence as the Proxy classes would need to be updated on oc4j.jar.
- In this OC4J configuration step we will use a copy of EclipseLink local to the EAR and reference any dependent jars in the xml config files.
- Create a new org.eclipse.persistence directory off of $OC4J_ROOT/shared-lib with a subdirectory n.n.n for this specific version - the jars will be placed and referenced here.
C:\opt\oc4j101n\j2ee\home\shared-lib\org.eclipse.persistence\n.n.n\
- Edit $OC4J_ROOT/config/server.xml and add the following shared-library element above the existing oracle.persistence.
- Note: 20100712 changed and verified path="*.jar" below to "path="../shared-lib/org.eclipse.persistence/2.1.0/*.jar"
<shared-library name="org.eclipse.persistence" version="2.1.0" library-compatible="true"> <!-- jars are referenced relative to the name/version directory --> <code-source path="../shared-lib/org.eclipse.persistence/2.1.0/eclipselink.jar"/> <code-source path="../shared-lib/org.eclipse.persistence/2.1.0/javax.persistence/2.0.1.v201006031150.jar"/> <import-shared-library name="oracle.jdbc"/> </shared-library>
Note: Notice that we are picking up the shipped oracle.jdbc library in the last line - we don't need to redeploy this jar to the server.
- Add the following import-shared-library element above the existing two shared libraries oracle.persistence and oracle.toplink in $OC4J_ROOT/config/system-application.xml around line 30.
<imported-shared-libraries> <!-- new EclipseLink shared library --> <import-shared-library name="org.eclipse.persistence"/> <!-- existing shipped out-of-the-box libraries --> <import-shared-library name="oracle.toplink"/> <import-shared-library name="oracle.persistence"/>
- Restart or start the server to pickup changes.
- You should see the following to start
[EL Finest]: 2010-07-12 14:48:34.285--ServerSession(19397123)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--Begin deploying Persistence Unit example; session file:/C:/opt/oc4j10135/j2ee/home/applications/org.eclipse.persistence.example.jpa.server.oc4j.enterpriseEAR/ org.eclipse.persistence.example.jpa.server.oc4j.enterpriseEJB.jar_example; state Predeployed; factoryCount 1
20100712 in progress
- Currently gathering configuration details to get past the JPA 2.0 invisibility to the ejb container classloader.
- Essentially this issue is that the class EntityManagerProxy - an implementation class used for EntityManager injection is not updated to implement the new JPA 2.0 functions.
- A call to em.getCriteriaBuilder() in a stateless session bean will fail with com.evermind.server.ejb.persistence.EntityManagerProxy.getCriteriaBuilder()Ljavax/persistence/criteria/CriteriaBuilder;
- @PersistenceUnit injection is not available - we will need to defer to application managed persistence
[EL Finest]: 2010-07-12 14:48:35.437--ServerSession(19397123)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--End deploying Persistence Unit example; session file:/C:/opt/oc4j10135/j2ee/home/applications/org.eclipse.persistence.example.jpa.server.oc4j.enterpriseEAR/org.eclipse.persistence.example.jpa.server.oc4j.enterpriseEJB.jar_example; state Deployed; factoryCount 1 2010-07-12 14:48:35.757 ERROR J2EE EJB-08006 [ApplicationService:public java.util.List org.eclipse.persistence.example.jpa.server.business.ApplicationService.query(java.lang.String)] exception occurred during method invocation: javax.ejb.EJBException: java.lang.AbstractMethodError: com.evermind.server.ejb.persistence.EntityManagerProxy.getCriteriaBuilder()Ljavax/persistence/criteria/CriteriaBuilder; 10/07/12 14:48:35 javax.ejb.EJBException: java.lang.AbstractMethodError: com.evermind.server.ejb.persistence.EntityManagerProxy.getCriteriaBuilder()Ljavax/persistence/criteria/CriteriaBuilder; 10/07/12 14:48:35 at com.evermind.server.ejb.EJBUtils.getLocalUserException(EJBUtils.java:337)
- see overrides
- C:\opt\oc4j10135\j2ee\home\lib\persistence.jar
- C:\opt\oc4j10135\toplink\jlib\preview-persistence.jar
- working
The missing class is available from the following locations: 1. Code-Source: /C:/opt/oc4j10135/j2ee/home/shared-lib/org.eclipse.persistence/2.1.0/javax.persistence_2.0.1.v201006031150.jar (from <code-source> in /C:/opt/oc4j10135/j2ee/home/config/server.xml) This code-source is available in loader org.eclipse.persistence:2.1.0. This shared-library can be made visible to the "oc4j" loader by modifying the boot descriptor.
- boot.xml defines 2 paths to javax.persistence based on the provider name "TopLink" or !TopLink
- <code-source path="lib/persistence.jar" if="default.persistence.provider != toplink"/>
- <code-source path="${oracle.home}/toplink/jlib/preview-persistence.jar"
- if="default.persistence.provider == toplink"/>
- Hacking boot.xml is not currently working
- adding at the root
- <code-source path="lib/javax.persistence_2.0.1.v201006031150.jar"/>
- we get
- adding at the root
10/07/12 15:44:11 SEVERE: Unable to access code-source: /C:/opt/oc4j10135/j2ee/home/lib/persistence.jar (from <code-source> (ignore manifest Class-Path) in META-INF/boot.xml in C:\opt\oc4j10135\j2ee\home\oc4j.jar). Caught java.util.zip.ZipException: error in opening zip file 10/07/12 15:44:12 SEVERE: Could not read manifest of: /C:/opt/oc4j10135/j2ee/home/lib/persistence.jar (from <code-source> (ignore manifest Class-Path) in META-INF/boot.xml in C:\opt\oc4j10135\j2ee\home\oc4j.jar) Caught java.util.zip.ZipException: error in opening zip file
Linking source to binaries and debugging EclipseLink - optional step
- Developers may want to debug EclipseLink, the EclipseLink nightly build compiles a debug ready jar using the following debug parameters in build.properties.
javac.debug=true javac.debuglevel=lines,vars,source
- The following file available at the SVN trunk can be used to view EclipseLink source in an IDE - you will want to place this jar into your new 'eclipselink shared-library folder.
- eclipselink-src.zip
JDBC JAR location
- There is an existing Oracle jdbc driver in OC4J_ROOT/../jdbc/lib/orai18n.jar that is referenced by the existing toplink shared library and if you follow option 1 will be referenced by the new eclipselink shared library.
- Or, copy your specific jdbc driver jar to $OC4J_ROOT/applib if you use option 3
Create server in Eclipse
Open the servers view New | Server | Oracle | Oracle OC4J Standalone Server 10.1.3.n (it is ok to use this one for 10.1.3.5). The only default you may need to change is the admin user from oc4jadmin to fmwadmin.
Verify OC4J server launch from Eclipse
You will see the following after starting the server from the servers' tab - no TopLink product interaction happens yet.
09/02/26 09:55:00 Oracle Containers for J2EE 10g (10.1.3.5.0) initialized
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
- Path changes may be required depending on your Eclipse WTP setup - I did not require links to these core projects
<classpathentry combineaccessrules="false" kind="src" path="/javax.persistence 1.0.0"/> <classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.persistence.jpa"/>
- After EAR project creation - reference eclipselink.core and eclipselink.jpa or include a reference to eclipselink.jar in your WAR project if required.
UML Data Model
The following single entity Cell has a @ManyToMany bidirectional relationship to itself.
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 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 managed SE app.
- 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 when using a stateless session bean - hence the use of a separate project that is server agnostic and sharable by all the JPA Web application tutorials in this section of the Wiki.
Persistence.xml
JTA Datasource
- 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 Home >Summary of JDBC Data Sources - either prefixed with jdbc/ or not.
<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="example" transaction-type="JTA"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <jta-data-source>jdbc/OracleDS</jta-data-source> <class>org.eclipse.persistence.example.jpa.server.business.Cell</class> <properties> <property name="eclipselink.target-server" value="OC4J"/> <property name="eclipselink.logging.level" value="FINEST"/> </properties> </persistence-unit> </persistence>
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
- Eclipse WTP will take care of dynamically generating all the orion*.xml files required by OC4J when you either [re-publish] or modify any files while the server is running.
- You may also use any combination of running the OC4J server yourself in run or debug mode and using eclipse to publish EAR changes.
- In the predeploy EAR Ant task you should see weaving messages for your entities if logs are set to FINEST in persistence.xml
- Depending on your application you will see the following after running [start server]
- In your console window you will see two processes - one for the server and the second for the deploy target.
- If you click on the server console you will see the predeploy weaving logs
[EL Finest]: 2009-02-26 16:03:31.043--ServerSession(8665869)--Thread(Thread[OC4J Launcher,5,main])--Begin predeploying Persistence Unit example; state Initial; factoryCount 0 [EL Finest]: 2009-02-26 16:03:32.809--ServerSession(8665869)--Thread(Thread[OC4J Launcher,5,main])--Weaved persistence (PersistenceEntity) [org/eclipse/persistence/example/jpa/server/business/Cell]. 09/02/26 16:03:32 Oracle Containers for J2EE 10g (10.1.3.5.0) initialized
Perform a JPQL query
- 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:8888/enterprise/FrontController?action=demo
- This url command gets a container managed EntityManager via @EJB injection of the ApplicationServiceLocal Stateless Session Bean which contains and injected @PersistenceContext EntityManager reference.
public class FrontController extends HttpServlet implements Servlet { @EJB(beanName="ApplicationService") public ApplicationServiceLocal applicationService; ... @Local public interface ApplicationServiceLocal { ... @Local @Stateless public class ApplicationService implements ApplicationServiceLocal { @PersistenceContext(unitName="example") private EntityManager entityManager; ...
Console Output
[EL Finest]: 2009-02-26 14:04:34.464--ServerSession(8634980)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--Begin deploying Persistence Unit example; state Predeployed; factoryCount 1 [EL Info]: 2009-02-26 14:04:34.542--ServerSession(8634980)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--EclipseLink, version: Eclipse Persistence Services - *** [EL Fine]: 2009-02-26 14:04:35.213--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--Detected Vendor platform: org.eclipse.persistence.platform.database.oracle.Oracle10Platform [EL Config]: 2009-02-26 14:04:35.26--ServerSession(8634980)--Connection(5230779)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--Connected: jdbc:oracle:thin:@//127.0.0.1:1521/ORCL User: SCOTT Database: Oracle Version: Oracle Database 11g Release 11.1.0.0.0 - Production Driver: Oracle JDBC driver Version: 10.1.0.5.0 [EL Finest]: 2009-02-26 14:04:35.385--UnitOfWork(5746770)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--PERSIST operation called on: org.eclipse.persistence.example.jpa.server.business.Cell@9107088( id: null state: null left: null right: null parent: null references: null). [EL Fine]: 2009-02-26 14:04:35.807--ClientSession(5748500)--Connection(6653899)--Thread(Thread[HTTPThreadGroup-4,5,HTTPThreadGroup])--INSERT INTO EL_CELL (ID, STATE, TSEQ, RIGHT_ID) VALUES (?, ?, ?, ?) bind => [551, null, null, null]
Browser Output
The following screen capture of this quickstart JEE OC4J JPA application shows a visual representation of the entities persisted to the Oracle database using the EclipseLink JPA implementation on Oracle OC4J Server 10.1.3.5.
Troubleshooting
References
- See Integrating EclipseLink with an Application Server in the ELUG
- See Developing JPA Projects in the EclipseLink User's Guide.
- See EclipseLink Architecture and UML Diagrams
- See OC4J 10.1.3.5 OTN Download