Skip to main content

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

Jump to: navigation, search

EclipseLink/Examples/JPA/WebSphere Web Tutorial6

EclipseLink JPA Deployed on IBM WebSphere 6.1 using Eclipse WTP

Note: This tutorial' is under construction for the next week as of 20080918.

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 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 DALI project was used to generate Entities from a schema with sequences already populated.

Development Environment

Software: 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), Derby Database 10.4, Java JDK 1.6.0_04, IBM WebSphere 6.1.0.0 with EJB3/JPA1 update

This example will run fine with any Database that EclipseLink supports.

Prerequisites

Install Eclipse EE

  • I installed a clean version of Eclipse Ganymede (June 2008) with all of WTP 3.0

Install a Database

  • In this example I am using the embedded Derby 10.4, the table schemas have already been created manually and all entity java classes may be generated using the Eclipse DALI tool.
  • There is also an express version of IBM DB2 Express C 9.5 available

Install WebSphere 6.1

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 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

Was61 admin datasource derby create true.JPG

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

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.

Was61 admin env shared lib1.JPG

  • Save the shared-library change and restart the server.

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
<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>
  • 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
  <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>

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.

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.

[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/myyyy-pc2Node01Cell/unifiedWAS6EAR.ear/unifiedWAS6EJB.jar!/ module.

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.

************ 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 myyyy-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
[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

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


Originated on build 20080918 - Michael O'Brien

Back to the top