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.
Difference between revisions of "EclipseLink/Examples/JPA/WebSphere7 Web Tutorial"
m (→JPA 1.0 persistence.xml) |
m (→@PersistenceUnit EMF injection on WAR Servlet) |
||
Line 157: | Line 157: | ||
=====<font color="green">'''JPA 1.0 persistence.xml'''</font>===== | =====<font color="green">'''JPA 1.0 persistence.xml'''</font>===== | ||
*Both '''Persistence''' boostrap and '''@PersistenceUnit''' injection work well on an application managed EclipseLink JPA 1.0 client like a servlet in the WAR in an EAR on WebSphere 7.0. | *Both '''Persistence''' boostrap and '''@PersistenceUnit''' injection work well on an application managed EclipseLink JPA 1.0 client like a servlet in the WAR in an EAR on WebSphere 7.0. | ||
− | ======WebContent/META-INF/MANIFEST.MF===== | + | ======WebContent/META-INF/MANIFEST.MF====== |
*Manifest entry on the WAR must reference the libraries in the EAR project | *Manifest entry on the WAR must reference the libraries in the EAR project | ||
**Class-Path: APP-INF/lib/eclipselink.jar | **Class-Path: APP-INF/lib/eclipselink.jar | ||
*** APP-INF/lib/javax.persistence_2.0.0.v201002051058.jar | *** APP-INF/lib/javax.persistence_2.0.0.v201002051058.jar | ||
− | + | ======Servlet client====== | |
*Injection of EMF on servlet | *Injection of EMF on servlet | ||
+ | <source lang="java"> | ||
+ | public class FrontController extends HttpServlet implements Servlet { | ||
@PersistenceUnit(unitName="example-am1") | @PersistenceUnit(unitName="example-am1") | ||
private EntityManagerFactory emf; | private EntityManagerFactory emf; | ||
+ | </source> | ||
======Persistence.xml 1.0 version====== | ======Persistence.xml 1.0 version====== | ||
<source lang="xml"> | <source lang="xml"> | ||
Line 182: | Line 185: | ||
</persistence> | </persistence> | ||
</source> | </source> | ||
+ | |||
+ | ======Console logs====== | ||
+ | [4/16/10 16:21:55:359 EDT] 0000001a SystemOut O [EL Finest]: 2010-04-16 16:21:55.359--ServerSession(439228974)--Thread(Thread[WebContainer : 4,5,main])--Begin predeploying Persistence Unit example-am1; session file:/C:/opt/was7001/AppServer/profiles/AppSrv01/installedApps/beowulf5Node01Cell/org.eclipse.persistence.example.jpa.server.websphere.EnterpriseEAR.ear/org.eclipse.persistence.example.jpa.server.websphere.EnterpriseWeb.war/_example-am1; state Initial; factoryCount 0 | ||
+ | |||
+ | [4/16/10 16:23:51:640 EDT] 0000001d SystemOut O [EL Finest]: 2010-04-16 16:23:51.64--ServerSession(1268927394)--Thread(Thread[WebContainer : 7,5,main])--Begin weaver class transformer processing class [org.eclipse.persistence.example.jpa.server.business.Cell]. | ||
+ | [4/16/10 16:23:51:718 EDT] 0000001d SystemOut O [EL Finest]: 2010-04-16 16:23:51.718--ServerSession(1268927394)--Thread(Thread[WebContainer : 7,5,main])--Weaved persistence (PersistenceEntity) [org.eclipse.persistence.example.jpa.server.business.Cell]. | ||
+ | [4/16/10 16:23:51:718 EDT] 0000001d SystemOut O [EL Finest]: 2010-04-16 16:23:51.718--ServerSession(1268927394)--Thread(Thread[WebContainer : 7,5,main])--Weaved fetch groups (FetchGroupTracker) [org.eclipse.persistence.example.jpa.server.business.Cell]. | ||
+ | [4/16/10 16:23:51:828 EDT] 0000001d SystemOut O Persistence.createEntityManagerFactory(example-am1): = org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl@5dc85dc8 | ||
+ | [4/16/10 16:23:53:515 EDT] 0000001d SystemOut O Injected @PersistenceUnit: org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl@5dc85dc8 | ||
+ | [4/16/10 17:03:28:312 EDT] 00000019 SystemOut O EntityManager from Injected @PersistenceUnit: org.eclipse.persistence.internal.jpa.EntityManagerImpl@4cfc4cfc | ||
+ | [4/16/10 16:23:53:421 EDT] 0000001d SystemOut O [EL Finer]: 2010-04-16 16:23:53.421--ServerSession(439228974)--Thread(Thread[WebContainer : 7,5,main])--Canonical Metamodel class [org.eclipse.persistence.example.jpa.server.business.Cell_] not found during initialization. | ||
+ | [4/16/10 16:23:53:500 EDT] 0000001d SystemOut O [EL Finer]: 2010-04-16 16:23:53.5--ServerSession(439228974)--Thread(Thread[WebContainer : 7,5,main])--client acquired | ||
+ | [4/16/10 16:23:53:515 EDT] 0000001d SystemOut O [EL Finest]: 2010-04-16 16:23:53.515--UnitOfWork(758525238)--Thread(Thread[WebContainer : 7,5,main])--PERSIST operation called on: org.eclipse.persistence.example.jpa.server.business.Cell@165349851( id: null state: null left: null right: null parent: HashSet@165874147 references: HashSet@165874147). | ||
+ | [4/16/10 16:23:53:859 EDT] 0000001d SystemOut O [EL Finest]: 2010-04-16 16:23:53.859--UnitOfWork(859058996)--Thread(Thread[WebContainer : 7,5,main])--Execute query ReadAllQuery(referenceClass=Cell sql="SELECT ID, STATE, TSEQ, RIGHT_ID, ACELLATTRIBUTE_ID FROM EL_CELL") | ||
+ | |||
+ | |||
+ | |||
+ | |||
=====<font color="red">JPA 2.0 persistence.xml</font>===== | =====<font color="red">JPA 2.0 persistence.xml</font>===== |
Revision as of 17:26, 16 April 2010
Contents
- 1 EclipseLink JPA Deployed on IBM WebSphere 7 using Eclipse WTP
- 2 Container Managed and Application Managed Scenarios
- 2.1 Configuration
- 2.2 Container Managed
- 2.3 Application Managed
- 2.4 Persistence JAR location
- 2.5 EclipseLink JAR location
- 2.6 JDBC JAR location
- 3 EAR Creation, Deployment and testing
EclipseLink JPA Deployed on IBM WebSphere 7 using Eclipse WTP
- This tutorial needs to be finished and/or expanded - as of 20100415 - I have approval to update this wiki via bug# bug# 309201.
Note: This tutorial' is under construction for the next week as of 200100415.
If you want to get a small web application running quickly on WebSphere 7.0 you can use Eclipse to create the EAR and attach to a running WebSphere instance in debug mode on port 7781.
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 required to run EclipseLink inside the IBM WebSphere Application Server 7.0 server 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.
Development Environment
Software
- http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/galileo/SR2/eclipse-jee-galileo-SR2-win32.zip Eclipse IDE for Java EE 3.5 Galileo SR 2] (April 2010 +) IBM J9 JRE 1.6.0 build 2.4 20080816_22093.
OS
- Normally I would install and run this on my Corei7 64-bit Windows7 12Gb machine - however there are issues installing the version of WebSphere 7.0.0.5 on this 64-bit version of windows. I installed on an alternate vintage XP SP3 32-bit P640 machine where it runs fine.
- Note: Developing/Debugging an enterprise application works excellent if you use IBM Rational Developer as the Eclipse based IDE where 7.0 server support currently exists. However if you wish to debug from an unenhanced standard Eclipse 3.5 EE IDE you must run through some hoops and export your EAR manually, deploy/update it in the admin console and attach to the debuggable process manually. In other application servers such as WebLogic, OC4J, Glassfish, Tomcat and even WebSphere 6.0 this process is handled automatically for you via an eclipse plugin.
Prerequisites
Install Eclipse EE
- I installed a clean version of Eclipse Galileo 3.5 SR2 EE Edition (32-bit) (April 2010) on a Window 7 64-bit install where the default JRE was the 64-Bit server version of the SUN JVM. I therefore needed to override the default java.exe by specifying the following shortcut override
C:\eclipse35-32bit-home\eclipse.exe -vm c:/jdk1.6.0_32-bit/bin/java.exe
- Default eclipse.ini settings must be modified as referenced.
Install a Database
- We will be using a remote Oracle 11 instance as well as a local Derby 10.5.3.0 instance or the embedded Derby instance that comes with WebSphere.
Install WebSphere 7.0
- I installed the commercial 7.0.0.0 version of IBM WebSphere 7 and then the 7.0.0.5 fixpack in 7.0.0-WS-WAS-WinX32-FP0000005.pak using the 7.0.0.5-WS-UPDI-WinIA32.zip installer.
Install WebSphere Eclipse 3.4 Server Plugin - unusable
We will first see if the WebSphere 6.0 or 6.1 plugin works with WebSphere 7.0 - it fails on missing jar files that are not present in 7.0. The WebSphere 6.1 Eclipse WTP server plugin is not shipped by default with Eclipse (WebSphere 6.0 for JEE 1.4 is).
- Note: The WebSphere 6.1 plugin for Eclipse WTP is currently being developed - see the following Eclipse WTP enhancement request 160220 in progress.
- We are not blocked from using Eclipse WTP to manage the WebSphere 6.1 server, but without this plugin we will need to attach manually to port 7781 of a running WebSphere server that was started in debug mode outside of the Eclipse IDE - we will use this alternate debug approach.
- If you try to stub out the 73 jars required by the WebSphere 6.0 plugin to make it work with a WebSphere 7.0 server - you will get the following exception starting WebSphere from Eclipse. - so don't do it
com.ibm.ws.exception.ConfigurationError: java.lang.Exception: Cannot find BundleContext for service com.ibm.ws.runtime.config.ConfigServiceImpl at com.ibm.ws.runtime.WsServerImpl.bootConfigService(WsServerImpl.java:335) at com.ibm.ws.runtime.WsServerImpl.start(WsServerImpl.java:171)
WebSphere Configuration Changes
- WebSphere configuration modifications can be done on the admin console .
- http://localhost:9060/ibm/console/
- Which redirects to
- https://localhost:9043/ibm/console/login.do?action=secure
- or if a secure login was not selected
- http://localhost:9060/ibm/console/unsecureLogon.jsp
JNDI Datasource Setup
Global Scoped Datasource Setup
- We will for now use the already configured JNDI name "DefaultDatasource".
- Note the check box "Use this data source in container managed persistence (CMP)" that allows us to use this TX datasource for all our container managed deployments below.
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
Container Managed and Application Managed Scenarios
- The following table summarizes the type of test, server modifications and results for verious container managed and application managed EntityManager deployments on the IBM WebSphere 7 server.
UC# DI# | Test Example-Description | Container-Managed vs Application-Managed | Injected-EMF vs Persistence bootstrap | JTA, non-JTA, RESOURCE _LOCAL Datasource | Entities, PU in utility JAR | Entities, PU in EJB JAR | Entities, PU in WAR | EAR wls:prefer- application-packages mod? | Server modifications? | persistence.xml 2.0 XSD Schema | Weaving entities | Runs JPA2 Impl (shipped with EclipseLink 1.2 only) | Runs JPA2 Impl (shipped with EclipseLink 2.0 only) - IE: CriteriaBuilder |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
#N | Container-Managed PU in EAR(EJB,WAR) - working with server mod | container | injected @PersistenceContext EM on SLSB | JTA (derby XA) | PU in EJB | eclipselink.jar in %server%/lib | 1.0 only | Weaved as 1.0 | ? | ? |
Configuration
- URL
- This section is currently undergoing editing as these deployments are tested today (20100416)
- The following section details investigations on what configurations work when using the EclipseLink JPA provider on the IBM WebSphere 7 Application Server. The test deployments are configured around container managed EARs that require server modification such as creating a global shared library or placing the eclipselink.jar library directly in the %SERVER%/lib, and application managed EARs that do not require any server modification as they ship the required libraries as part of the EAR.
Container Managed
EAR configuration
- standard @EJB statless session bean injected on Servlet client, the EJB bean is @PersistenceContext injected with a container managed EntityManager using a transactional datasource (in this case derby)
- Server startup logs
WebSphere Platform 7.0.0.5 [BASE 7.0.0.5 cf050926.18] running with process name beowulf5Node01Cell\beowulf5Node01\server1 and process id 2928 Host Operating System is Windows XP, version 5.1 build 2600 Service Pack 3 Java version = 1.6.0, Java Compiler = j9jit24, Java VM name = IBM J9 VM
EclipseLink library in Server/lib
- Placing the eclipselink.jar library directly on the server in the %SERVER%/lib directory and restarting the server will allow container managed deployments of EclipseLink applications following the JPA 1.0 specification to inject and function correctly.
Predeploy, deploy and runtime logs
[4/16/10 10:26:39:484 EDT] 0000000a SystemOut O [EL Finest]: 2010-04-16 10:26:39.343--ServerSession(112920251)--Thread(Thread[server.startup : 1,5,main])--Begin predeploying Persistence Unit example; session jar:file:/C:/opt/was7001/AppServer/profiles/AppSrv01/installedApps/beowulf5Node01Cell/org.eclipse.persistence.example.jpa.server.websphere.EnterpriseEAR.ear/org.eclipse.persistence.example.jpa.server.websphere.EnterpriseEJB.jar!/_example; state Initial; factoryCount 0 [4/16/10 10:26:40:218 EDT] 0000000a SystemOut O [EL Finer]: 2010-04-16 10:26:40.218--ServerSession(112920251)--Thread(Thread[server.startup : 1,5,main])--Class [org.eclipse.persistence.example.jpa.server.business.Cell] registered to be processed by weaver. [4/16/10 10:26:40:312 EDT] 0000000a SystemOut O [EL Finest]: 2010-04-16 10:26:40.312--ServerSession(1551588475)--Thread(Thread[server.startup : 1,5,main])--End predeploying Persistence Unit exampleAM; session jar:file:/C:/opt/was7001/AppServer/profiles/AppSrv01/installedApps/beowulf5Node01Cell/org.eclipse.persistence.example.jpa.server.websphere.EnterpriseEAR.ear/org.eclipse.persistence.example.jpa.server.websphere.EnterpriseEJB.jar!/_exampleAM; state Predeployed; factoryCount 1 [4/16/10 10:26:44:078 EDT] 0000000a EJBContainerI I WSVR0057I: EJB jar started: org.eclipse.persistence.example.jpa.server.websphere.EnterpriseEJB.jar [4/16/10 10:27:23:781 EDT] 00000012 SystemOut O [EL Finest]: 2010-04-16 10:27:23.781--ServerSession(112920251)--Thread(Thread[WebContainer : 1,5,main])--Begin weaver class transformer processing class [org.eclipse.persistence.example.jpa.server.business.Cell]. [4/16/10 10:27:23:843 EDT] 00000012 SystemOut O [EL Finest]: 2010-04-16 10:27:23.843--ServerSession(112920251)--Thread(Thread[WebContainer : 1,5,main])--Weaved persistence (PersistenceEntity) [org.eclipse.persistence.example.jpa.server.business.Cell]. [4/16/10 10:27:23:843 EDT] 00000012 SystemOut O [EL Finest]: 2010-04-16 10:27:23.843--ServerSession(112920251)--Thread(Thread[WebContainer : 1,5,main])--Weaved fetch groups (FetchGroupTracker) [org.eclipse.persistence.example.jpa.server.business.Cell]. [4/16/10 10:27:23:843 EDT] 00000012 SystemOut O [EL Finest]: 2010-04-16 10:27:23.843--ServerSession(112920251)--Thread(Thread[WebContainer : 1,5,main])--End weaver class transformer processing class [org.eclipse.persistence.example.jpa.server.business.Cell]. [4/16/10 10:27:26:953 EDT] 00000012 SystemOut O [EL Config]: 2010-04-16 10:27:26.953--ServerSession(112920251)--Connection(292491631)--Thread(Thread[WebContainer : 1,5,main])--Connected: jdbc:derby:C:\opt\was7001\AppServer\profiles\AppSrv01/installedApps/beowulf5Node01Cell/DefaultApplication.ear/DefaultDB [4/16/10 10:27:27:312 EDT] 00000012 SystemOut O [EL Finest]: 2010-04-16 10:27:27.312--UnitOfWork(67175425)--Thread(Thread[WebContainer : 1,5,main])--PERSIST operation called on: org.eclipse.persistence.example.jpa.server.business.Cell@562176386( id: null state: null left: null right: null parent: HashSet@562700682 references: HashSet@562700682). [4/16/10 10:27:27:359 EDT] 00000012 SystemOut O [EL Fine]: 2010-04-16 10:27:27.359--ClientSession(488447261)--Connection(18219286)--Thread(Thread[WebContainer : 1,5,main])--INSERT INTO EL_CELL (STATE, TSEQ, ACELLATTRIBUTE_ID, RIGHT_ID) VALUES (?, ?, ?, ?)
No EclipseLink library on the Server or the EAR
- This is not a valid configuration because the EclipseLink JPA provider library is not shipped by default with WebSphere.
- You will see the following exception if you attempt to use the org.eclipse.persistence.jpa.PersistenceProvider in this case. This forms a good base case failure test upon which the other valid scenarios can be verified against.
- javax.ejb.EJBException: Injection failure; nested exception is: java.lang.IllegalStateException: EntityManagerFactory has not been created for PU : PuId=org.eclipse.persistence.example.jpa.server.websphere.EnterpriseEAR#org.eclipse.persistence.example.jpa.server.websphere.EnterpriseEJB.jar#example
Application Managed
EAR configuration
- standard Persistence static bootstrap EMF on the servlet or @PersistenceUnit injection on the servlet with a non-JTA datasource or direct JDBC connection (in this case derby)
Eclipselink library in EAR
Static Persistence bootstrap EMF creation in WAR Servlet
Static Persistence bootstrap EMF creation in EJB Session Bean
- placing the eclipselink.jar in the EAR and attempting to use the SE Persistence bootstrap class to create an EMF on a Stateless Session Bean - in the EJB.jar - (on the EJB container instead of the WEB container) does not work because the classloader position of the eclipselink.jar is not visible to the JPA 1.0 persistence library that ships with the server higher up.
- You see the following warnings
[4/16/10 11:23:09:218 EDT] 0000001d SystemErr R WARNING: Unable to load persistence provider "org.eclipse.persistence.jpa.PersistenceProvider" due to "java.lang.ClassNotFoundException: org.eclipse.persistence.jpa.PersistenceProvider" [4/16/10 11:23:09:218 EDT] 0000001d SystemErr R WARNING: Found unrecognized persistence provider "org.eclipse.persistence.jpa.PersistenceProvider" in place of OpenJPA provider. This provider's properties will not be used.
- You will get a null EntityManagerFactory when attempting
EntityManagerFactory emf = Persistence.createEntityManagerFactory("example");
@PersistenceUnit EMF injection on WAR Servlet
- This is the recommended application managed way of getting an EMF.
JPA 1.0 persistence.xml
- Both Persistence boostrap and @PersistenceUnit injection work well on an application managed EclipseLink JPA 1.0 client like a servlet in the WAR in an EAR on WebSphere 7.0.
WebContent/META-INF/MANIFEST.MF
- Manifest entry on the WAR must reference the libraries in the EAR project
- Class-Path: APP-INF/lib/eclipselink.jar
- APP-INF/lib/javax.persistence_2.0.0.v201002051058.jar
- Class-Path: APP-INF/lib/eclipselink.jar
Servlet client
- Injection of EMF on servlet
public class FrontController extends HttpServlet implements Servlet { @PersistenceUnit(unitName="example-am1") private EntityManagerFactory emf;
Persistence.xml 1.0 version
<persistence 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" version="1.0"> <!-- persistence 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 persistence_2_0.xsd" version="2.0"--> <persistence-unit name="example-am1" transaction-type="JTA"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <!-- shared-cache-mode>NONE</shared-cache-mode--> <!-- JPA 2.0 PFD only --> <jta-data-source>DefaultDatasource</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="WebSphere_7"/> <property name="eclipselink.logging.level" value="FINEST"/> </properties> </persistence-unit> </persistence>
Console logs
[4/16/10 16:21:55:359 EDT] 0000001a SystemOut O [EL Finest]: 2010-04-16 16:21:55.359--ServerSession(439228974)--Thread(Thread[WebContainer : 4,5,main])--Begin predeploying Persistence Unit example-am1; session file:/C:/opt/was7001/AppServer/profiles/AppSrv01/installedApps/beowulf5Node01Cell/org.eclipse.persistence.example.jpa.server.websphere.EnterpriseEAR.ear/org.eclipse.persistence.example.jpa.server.websphere.EnterpriseWeb.war/_example-am1; state Initial; factoryCount 0
[4/16/10 16:23:51:640 EDT] 0000001d SystemOut O [EL Finest]: 2010-04-16 16:23:51.64--ServerSession(1268927394)--Thread(Thread[WebContainer : 7,5,main])--Begin weaver class transformer processing class [org.eclipse.persistence.example.jpa.server.business.Cell]. [4/16/10 16:23:51:718 EDT] 0000001d SystemOut O [EL Finest]: 2010-04-16 16:23:51.718--ServerSession(1268927394)--Thread(Thread[WebContainer : 7,5,main])--Weaved persistence (PersistenceEntity) [org.eclipse.persistence.example.jpa.server.business.Cell]. [4/16/10 16:23:51:718 EDT] 0000001d SystemOut O [EL Finest]: 2010-04-16 16:23:51.718--ServerSession(1268927394)--Thread(Thread[WebContainer : 7,5,main])--Weaved fetch groups (FetchGroupTracker) [org.eclipse.persistence.example.jpa.server.business.Cell]. [4/16/10 16:23:51:828 EDT] 0000001d SystemOut O Persistence.createEntityManagerFactory(example-am1): = org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl@5dc85dc8 [4/16/10 16:23:53:515 EDT] 0000001d SystemOut O Injected @PersistenceUnit: org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl@5dc85dc8 [4/16/10 17:03:28:312 EDT] 00000019 SystemOut O EntityManager from Injected @PersistenceUnit: org.eclipse.persistence.internal.jpa.EntityManagerImpl@4cfc4cfc [4/16/10 16:23:53:421 EDT] 0000001d SystemOut O [EL Finer]: 2010-04-16 16:23:53.421--ServerSession(439228974)--Thread(Thread[WebContainer : 7,5,main])--Canonical Metamodel class [org.eclipse.persistence.example.jpa.server.business.Cell_] not found during initialization. [4/16/10 16:23:53:500 EDT] 0000001d SystemOut O [EL Finer]: 2010-04-16 16:23:53.5--ServerSession(439228974)--Thread(Thread[WebContainer : 7,5,main])--client acquired [4/16/10 16:23:53:515 EDT] 0000001d SystemOut O [EL Finest]: 2010-04-16 16:23:53.515--UnitOfWork(758525238)--Thread(Thread[WebContainer : 7,5,main])--PERSIST operation called on: org.eclipse.persistence.example.jpa.server.business.Cell@165349851( id: null state: null left: null right: null parent: HashSet@165874147 references: HashSet@165874147). [4/16/10 16:23:53:859 EDT] 0000001d SystemOut O [EL Finest]: 2010-04-16 16:23:53.859--UnitOfWork(859058996)--Thread(Thread[WebContainer : 7,5,main])--Execute query ReadAllQuery(referenceClass=Cell sql="SELECT ID, STATE, TSEQ, RIGHT_ID, ACELLATTRIBUTE_ID FROM EL_CELL")
JPA 2.0 persistence.xml
- Application Managed EAR's that define a JPA 2.0 schema reference in their persistence.xml will not deploy.
<persistence 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 persistence_2_0.xsd" version="2.0">
- The following XML parsing error occurs on the server.
[4/16/10 15:45:50:093 EDT] 00000016 SystemErr R com.ibm.ws.exception.RuntimeWarning: com.ibm.ws.metadata.MetaDataException: CWWJP0040E: The persistence.xml in application org.eclipse.persistence.example.jpa.server.websphere.EnterpriseEAR, module org.eclipse.persistence.example.jpa.server.websphere.EnterpriseWeb.war, has a syntax error at line number: 20, column number: 209. [4/16/10 15:45:50:093 EDT] 00000016 SystemErr R at com.ibm.ws.jpa.management.JPAApplInfo.processModulePUs(JPAApplInfo.java:185) [4/16/10 15:45:49:250 EDT] 00000016 JPAPxmlInfo E CWWJP0040E: Incorrect syntax or error detected in the persistence.xml file in application: org.eclipse.persistence.example.jpa.server.websphere.EnterpriseEAR, module: org.eclipse.persistence.example.jpa.server.websphere.EnterpriseWeb.war, at line number: 20, column number: 209. The following associated error message occurred: javax.xml.bind.UnmarshalException - with linked exception: [org.xml.sax.SAXParseException: cvc-complex-type.3.1: Value '2.0' of attribute 'version' of element 'persistence' is not valid with respect to the corresponding attribute use. Attribute 'version' has a fixed value of '1.0'.] at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:326) Caused by: org.xml.sax.SAXParseException: cvc-complex-type.3.1: Value '2.0' of attribute 'version' of element 'persistence' is not valid with respect to the corresponding attribute use. Attribute 'version' has a fixed value of '1.0'. at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
- Also, if we try using JPA 2.0 API via a persistence.xml that is defined as JPA 1.0 so it passed deployment - we will still get an expected runtime exception when we try to use JPA 2.0 commands.
[4/16/10 16:08:47:578 EDT] 0000001b servlet E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: Uncaught exception created in one of the service methods of the servlet FrontController in application org.eclipse.persistence.example.jpa.server.websphere.EnterpriseEAR. Exception created : java.lang.NoSuchMethodError: javax/persistence/EntityManager.getMetamodel()Ljavax/persistence/metamodel/Metamodel; at org.eclipse.persistence.example.jpa.server.business.ApplicationManagedService.getMetamodel(ApplicationManagedService.java:139)
Persistence JAR location
- Where does the standard library plugins/com.ibm.ws.jpa.jar and runtimes/com.ibm.ws.jpa.thinclient_7.0.0.jar fit in? Is this a JPA spec jar or an OpenJPA implementation?
EclipseLink JAR location
JDBC JAR location
EAR Creation, Deployment and testing
Create J2EE application
Persistence.xml
Publish EAR
Validating the WebSphere/EclipseLink configuration
Without eclipselink.jar reference
With eclipselink.jar reference
Perform CRUD operations: JPQL insert and query
Browser Output
Remote Debugging EclipseLink in WebSphere 7.0 from Eclipse 3.4
The following procedure details how to attach to a debug version of IBM WebSphere 7.0 with the Eclipse 3.4 IDE.
Note: we will not be modifying startServer.bat. The java process in that script is only for server startup - if you need to debug this part of the server.
Modify console setup to start server in debug mode
- Login to the console using your admin login or a default username like system
- Navigate to Servers | Server Types | WebSphere Application servers | server1
- Navigate on the right down to Additional Properties | Debugging service
- Enable JDWP by ckecking the checkbox Enable service at server startup"
- The default properties below will be OK unmodified
- JVM debug port = 7781
- JVM debug arguments = -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=7781
- The default properties below will be OK unmodified
- Optionally you can add server packages if you have the source for WebSphere
- We will be debugging client test code and EclipseLink API in the Eclipse IDE
Start the WebSphere Server
Either run bin/startServer.bat or the following server ant test target in our suite.
<trunk>jpa\eclipselink.jpa.test>ant server-start
Attach Eclipse 3.4 to the debug port on WebSphere 7
- Right-click your test code
- Debug as | Debug Configurations
- select Remote Java Application
- create a new config by hitting the top-left new launch configuration icon
- type a name for your config and modify only the port to read 7781
- apply changes
- click debug
You should see the a stack trace ready for any breakpoints in your code that are hit - or suspend an orb thread to break into the code.
Deploy and Run EAR application
Depending on your breakpoints you will see a stacktrace hit in the Eclipse IDE similar to the following.
VirtualAttributeTestSuite [Remote Java Application] IBM J9 VM[localhost:7781] Thread [P=833989:O=0:CT] (Running) Daemon Thread [Signal Dispatcher] (Running) ... Daemon Thread [Thread-52] (Running) Daemon Thread [ORB.thread.pool : 0] (Running) Daemon Thread [ORB.thread.pool : 1] (Suspended (breakpoint at line 302 in ConcurrencyManager)) ConcurrencyManager.isAcquired() line: 302 ClientSession(AbstractSession).isInTransaction() line: 2405 ClientSession(AbstractSession).beginTransaction() line: 538 SequencingManager$Preallocation_Transaction_NoAccessor_State.getNextValue(Sequence, AbstractSession) line: 455 SequencingManager.getNextValue(AbstractSession, Class) line: 905 ClientSessionSequencing.getNextValue(Class) line: 70 ObjectBuilder.assignSequenceNumber(Object, AbstractSession) line: 277 RepeatableWriteUnitOfWork(UnitOfWorkImpl).assignSequenceNumber(Object, ClassDescriptor) line: 402 RepeatableWriteUnitOfWork(UnitOfWorkImpl).registerNotRegisteredNewObjectForPersist(Object, ClassDescriptor) line: 3952 RepeatableWriteUnitOfWork.registerNotRegisteredNewObjectForPersist(Object, ClassDescriptor) line: 359 RepeatableWriteUnitOfWork(UnitOfWorkImpl).registerNewObjectForPersist(Object, Map) line: 3899 EntityManagerImpl.persist(Object) line: 254 JPATxEmInvocation(JPAExEmInvocation).persist(Object) line: 336 JPATxEntityManager(JPAEntityManager).persist(Object) line: 123 VirtualAttributeTestSuite.testInsertVirtualAttribute() line: 63 NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method] NativeMethodAccessorImpl.invoke(Object, Object[]) line: 45 DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 37 Method.invoke(Object, Object...) line: 599 VirtualAttributeTestSuite(TestCase).runTest() line: 154 VirtualAttributeTestSuite(TestCase).runBare() line: 127 VirtualAttributeTestSuite(JUnitTestCase).runBareServer() line: 391 TestRunnerBean.runTest(String, String, Properties) line: 87 EJSRemote0SLTestRunner_ed643271.runTest(String, String, Properties) line: not available _EJSRemote0SLTestRunner_ed643271_Tie.runTest(InputStream, ResponseHandler) line: not available _EJSRemote0SLTestRunner_ed643271_Tie._invoke(String, InputStream, ResponseHandler) line: not available WSExtendedServerDelegate(ServerDelegate).dispatchInvokeHandler(InterceptorManager, ServerRequestInfoImpl, String, Object, ServerRequestReader) line: 622 WSExtendedServerDelegate(ServerDelegate).dispatch(ServerRequest) line: 475 ORB(ORB).process(ServerRequest) line: 504 ORB.process(ServerRequest) line: 1571 Connection.respondTo(RequestHandler, IIOPReader) line: 2771 Connection.doWork(RequestHandler, IIOPReader) line: 2640 WorkUnitImpl.doWork() line: 63 PooledThread.run() line: 118 ThreadPool$Worker.run() line: 1527 Daemon Thread [AIO Timer Thread 1] (Running) Daemon Thread [WebContainer : 0] (Running) ... Daemon Thread [RT=7:P=833989:O=0:WSTCPTransportConnection[addr=10.156.52.98,port=1553,local=9104]] (Running)
References
- See Developing JPA Projects in the EclipseLink User's Guide.
- http://www.ibm.com/developerworks/eclipse/downloads/ganymede/dev.html
History
- 20090115: Originated on build EclipseLink 1.1 M6 - Michael O'Brien
- 20100415: Updating for eclipselink.jar placement for container managed and application managed scenarios in EclipseLink enhancement # 309201