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/WebSphere Web Tutorial"

m (Download EclipseLink using SVN - developers only)
m (Replacing page with '=EclipseLink JPA Deployed on IBM WebSphere 6.1 using Eclipse WTP=')
Line 1: Line 1:
 
=EclipseLink JPA Deployed on IBM WebSphere 6.1 using Eclipse WTP=
 
=EclipseLink JPA Deployed on IBM WebSphere 6.1 using Eclipse WTP=
 
<font color="red">Note: This tutorial' is under construction for the next week as of 20080918.</font>
 
 
 
If you want to get a small web application running quickly on WebSphere 6.1 - the services provided by the '''Web Tools Project''' plugin in the '''Eclipse IDE''' can take care of the deployment details and set the server into debug mode 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 required to run EclipseLink inside the [http://www.ibm.com/developerworks/downloads/ws/was/?S_TACT=105AGX28&S_CMP=DLMAIN&S_CMP=rnav IBM WebSphere Application Server 6.1] 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 [http://wiki.eclipse.org/Dali 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/ganymede/R/eclipse-jee-ganymede-win32.zip Eclipse IDE for Java EE 3.4 Ganymede] (June 2008 +) with all 5 packages (DTP 1.6, EMF 2.4, GEF 3.4, WTP 3.0, XSD 2.4), [http://db.apache.org/derby Derby Database 10.4], Java JDK 1.6.0_04, [http://www.ibm.com/developerworks/downloads/ws/was/?S_TACT=105AGX28&S_CMP=DLMAIN&S_CMP=rnav IBM WebSphere 6.1.0.0 with EJB3/JPA1 update]
 
 
This example will run fine with any Database that EclipseLink supports.
 
 
==Prerequisites==
 
===<font color="green">Install Eclipse EE</font>===
 
*I installed a clean version of Eclipse Ganymede (June 2008) with all of WTP 3.0
 
 
===<font color="green">Install a Database</font>===
 
*In this example I am using the embedded [http://db.apache.org/derby Derby 10.4], the table schemas have already been created manually and all entity java classes may be generated using the Eclipse [http://wiki.eclipse.org/Dali DALI] tool.
 
*There is also an express version of [http://www-01.ibm.com/software/data/db2/express/ IBM DB2 Express C 9.5] available
 
===<font color="green">Install WebSphere 6.1</font>===
 
I installed the commercial 6.1.0.0 version with the EJB 3.0 fixpack and updates.
 
*download.updii.61017.windows.ia32.zip
 
*6.1.0-WS-WASSDK-WinX32-FP0000017.pak
 
*6.1.0-WS-WAS-WinX32-FP0000017.pak
 
*6.1.0-WS-WASEJB3-WinX32-FP0000017.pak
 
*I augumented the original server profile
 
 
 
===Install WebSphere Eclipse 3.4 Server Plugin===
 
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 [http://bugs.eclipse.org/160220 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 5005 of a running WebSphere server that was started in debug mode outside of the Eclipse IDE - we will use this alternate debug approach.
 
 
==WebSphere Configuration Changes==
 
WebSphere configuration modifications can be done on the admin console.
 
 
https://localhost:9043/ibm/console/login.do?action=secure
 
 
==JNDI Datasource Setup==
 
 
===Global Scoped Datasource Setup===
 
[[Image:Was61_admin_datasource_derby_create_true.JPG]]
 
 
==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 1.0.2 Installer Zip''' link which resolves to http://www.eclipse.org/downloads/download.php?file=/rt/eclipselink/releases/1.0.2/eclipselink-1.0.2.zip
 
*Expand the zip file and get the following 2 files
 
**eclipselink-1.0.2\eclipselink\jlib\eclipselink.jar
 
**eclipselink-1.0.2\eclipselink\jlib\jpa\javax.persistence_1.0.0.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 - ''(I am running rev 2.0.0.20090218-SNAPSHOT)''
 
**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
 
 
==Persistence JAR location==
 
WebSphere 6.1 (with EJB3 fixpack) comes with JPA support and will not need any other reference to the 1.0 specification persistence.jar
 
 
==EclipseLink JAR location==
 
*The eclipselink.jar will need to be setup as a shared library in the admin console off of the environment subtree.  The actual path to eclipselink.jar can be anything - I use the one built from SVN.
 
*Reference the full classpath to a copy of eclipselink.jar using a global scope.
 
[[Image:Was61_admin_env_shared_lib1.JPG]]
 
*Save the shared-library change and restart the server.
 
[[Image:Was61_admin_env_shared_lib2.JPG]]
 
 
==JDBC JAR location==
 
 
==Create J2EE application==
 
 
==Persistence.xml==
 
The WebSphere 6.1 server is defined as '''"WebSphere_6_1"'''
 
 
*JTA : Put persistence.xml beside your JPA entities in ''yourProjectEJB/ejbModule/META-INF'' 
 
<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-unit name="unified" transaction-type="JTA">
 
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
 
    <jta-data-source>jdbc/__default</jta-data-source>
 
    <properties>
 
      <property name="eclipselink.target-server" value="WebSphere_6_1"/>
 
      <property name="eclipselink.logging.level" value="FINEST"/>
 
      <property name="eclipselink.session-name" value="eclipselinkwls"/>
 
    </properties>
 
  </persistence-unit>
 
</persistence>
 
 
</source>
 
*RESOURCE_LOCAL : non-JTA : Put persistence.xml beside your JPA entities in ''yourProjectEJB/ejbModule/META-INF'' 
 
*This one is used by a local SE Java app to create and pre-populated the derby database
 
<source lang="xml">
 
  <persistence-unit name="stat.create.tables" transaction-type="RESOURCE_LOCAL">
 
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
 
    <class>entity..</class>
 
    <properties>
 
      <property name="eclipselink.jdbc.platform" value="oracle.toplink.platform.database.DerbyPlatform"/>
 
      <property name="eclipselink.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
 
      <property name="eclipselink.target-database" value="Derby"/>           
 
      <property name="eclipselink.jdbc.url" value="jdbc:derby:C:/opt/derby104/unified;create=true"/>
 
      <property name="eclipselink.jdbc.user" value="APP"/>
 
      <property name="eclipselink.jdbc.password" value="APP"/>
 
      <property name="eclipselink.logging.level" value="FINEST"/>           
 
      <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
 
      <property name="eclipselink.ddl-generation.output-mode" value="database"/>
 
    </properties>
 
  </persistence-unit>
 
</source>
 
 
==Publish EAR==
 
*Since the Eclipse WTP server plugin for WebSphere 6.1 is not available - we can deploy the EAR via the admin console or via python script.
 
[[Image:Was61_admin_deploy_app.JPG]]
 
===Validating the WebSphere/EclipseLink configuration===
 
*Start the server from the command-line or via windows service.
 
===Without eclipselink.jar reference===
 
You will see the following messages if the eclipselink JPA provider jar is not on the classpath.
 
 
<pre>
 
[9/19/08 10:59:44:320 EDT] 0000001d EJBContainerI I  CNTR0167I: The server is binding the ApplicationServiceLocal interface of the ApplicationService enterprise bean in the unifiedWAS6EJB.jar module of the unifiedWAS6EAR application.  The binding location is: ejblocal:unifiedWAS6EAR/unifiedWAS6EJB.jar/ApplicationService#org.eclipse.persistence.example.unified.business.ApplicationServiceLocal
 
[9/19/08 10:59:44:492 EDT] 0000001d ApplicationMg A  WSVR0221I: Application started: unifiedWAS6EAR
 
[9/19/08 10:59:48:195 EDT] 0000001c JPAPUnitInfo  E  CWWJP0009E: The server cannot create an EntityManangerFactory factory for the unified persistent unit from the org.eclipse.persistence.jpa.PersistenceProvider provider in jar:file:/C:/opt/was61/profiles/AppSrv01/installedApps/mxxxx-pc2Node01Cell/unifiedWAS6EAR.ear/unifiedWAS6EJB.jar!/ module.
 
</pre>
 
 
===With eclipselink.jar reference===
 
The following logs will verify that predeploy of our JPA application was successful on WebSphere using EclipseLink as the JPA provider.
 
 
<pre>
 
************ Start Display Current Environment ************
 
WebSphere Platform 6.1 [EJB3 6.1.0.17 cf170821.02] [BASE 6.1.0.17 cf170821.07]  running with process name mxxxx-pc2Node01Cell\mobrien-pc2Node01\server1 and process id 2608
 
Host Operating System is Windows XP, version 5.1 build 2600 Service Pack 2
 
Java version = J2RE 1.5.0 IBM J9 2.3 Windows XP x86-32 j9vmwi3223-20080315 (JIT enabled)
 
J9VM - 20080314_17962_lHdSMr
 
JIT  - 20080130_0718ifx2_r8
 
GC  - 200802_08, Java Compiler = j9jit23, Java VM name = IBM J9 VM
 
was.install.root = C:/opt/was61
 
user.install.root = C:\opt\was61\profiles\AppSrv01
 
Java Home = C:\opt\was61\java\jre
 
ws.ext.dirs = C:/opt/was61/java/lib;C:\opt\was61\profiles\AppSrv01/classes;C:/opt/was61/classes;C:/opt/was61/lib;C:/opt/was61/installedChannels;C:/opt/was61/lib/ext;C:/opt/was61/web/help;C:/opt/was61/deploytool/itp/plugins/com.ibm.etools.ejbdeploy/runtime
 
Classpath = C:\opt\was61\profiles\AppSrv01/properties;C:/opt/was61/properties;C:/opt/was61/lib/startup.jar;C:/opt/was61/lib/bootstrap.jar;C:/opt/was61/lib/j2ee.jar;C:/opt/was61/lib/lmproxy.jar;C:/opt/was61/lib/urlprotocols.jar;C:/opt/was61/deploytool/itp/batchboot.jar;C:/opt/was61/deploytool/itp/batch2.jar;C:/opt/was61/java/lib/tools.jar
 
Java Library path = C:\opt\was61\java\jre\bin;.;C:\opt\was61\bin;C:\opt\was61\java\bin;C:\opt\was61\java\jre\bin
 
</pre>
 
 
<pre>
 
[9/19/08 14:26:27:427 EDT] 00000014 SystemOut    O [EL Finest]: 2008.09.19 14:26:27.395--ServerSession(458103630)--Thread(Thread[server.startup : 2,5,main])--Begin predeploying Persistence Unit unified; state Initial; factoryCount 0
 
[9/19/08 14:26:27:958 EDT] 00000014 SystemOut    O [EL Config]: 2008.09.19 14:26:27.958--ServerSession(458103630)--Thread(Thread[server.startup : 2,5,main])--The column name for element [private java.math.BigInteger org.eclipse.persistence.example.unified.business.StatLabel.id] is being defaulted to: ID.
 
[9/19/08 14:26:28:145 EDT] 00000014 SystemOut    O [EL Finer]: 2008.09.19 14:26:28.145--ServerSession(458103630)--Thread(Thread[server.startup : 2,5,main])--Class [org.eclipse.persistence.example.unified.business.StatLabel] registered to be processed by weaver.
 
[9/19/08 14:26:28:161 EDT] 00000014 SystemOut    O [EL Finest]: 2008.09.19 14:26:28.161--ServerSession(458103630)--Thread(Thread[server.startup : 2,5,main])--End predeploying Persistence Unit unified; state Predeployed; factoryCount 1
 
</pre>
 
===Java 1.5 compiled eclipselink.jar is required for WebSphere 6.1===
 
IBM WebSphere 6.1 requires that the all jars are compiled as Java 1.5 compatible class files.
 
 
If you see the following UnsupportedClassVersionError - it just means that the version of eclipselink.jar you are using is compiled for a higher JRE than WebSphere is running - In my example I rebuilt it as a Java 1.6 binary but WebSphere expects Java 1.5 classes.
 
Verify what version of Java is running your WebSphere server by finding the process ID (PID) in task manager for your server and then attaching to this process using jconsole.exe
 
 
====Manifest from Broken JAR====
 
Created-By: 10.0-b19 (Sun Microsystems Inc.)
 
 
====Manifest from working JAR====
 
We are in luck because the Eclipse build server compiles eclipselink.jar using an IBM PowerPC server and an IBM Java 1.5 JVM.
 
 
Created-By: 2.3 (IBM Corporation)
 
 
Which matches the IBM 1.5 J9 JRE used by WebSphere 6.1
 
 
J2RE 1.5.0 IBM J9 2.3 Windows XP x86-32 j9vmwi3223-20080315 (JIT enabled)
 
 
==Perform CRUD operations: JPQL insert and query==
 
 
===Browser Output===
 
 
 
==References==
 
*See [[EclipseLink/UserGuide/Developing_JPA_Projects_%28ELUG%29|Developing JPA Projects]] in the EclipseLink User's Guide.
 
 
 
Originated on build 20080918 - Michael O'Brien
 

Revision as of 17:21, 24 March 2009

EclipseLink JPA Deployed on IBM WebSphere 6.1 using Eclipse WTP

Copyright © Eclipse Foundation, Inc. All Rights Reserved.