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

From Eclipsepedia

Jump to: navigation, search
m (New page: =EclipseLink JPA Deployed on IBM WebSphere CE 2.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...)
 
m (EclipseLink JPA Deployed on IBM WebSphere CE 2.1 using Eclipse WTP)
 
(13 intermediate revisions by one user not shown)
Line 1: Line 1:
 
=EclipseLink JPA Deployed on IBM WebSphere CE 2.1 using Eclipse WTP=
 
=EclipseLink JPA Deployed on IBM WebSphere CE 2.1 using Eclipse WTP=
 +
* <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>
  
 
<font color="red">Note: This tutorial' is under construction for the next week as of 20080918.</font>
 
<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 CE - 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.
If you want to get a small web application running quickly on GlassFish - the services provided by the '''Web Tools Project''' pluggin 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-01.ibm.com/software/webservers/appserv/community/ IBM WebSphere Application Server Community Edition] 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.
 
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-01.ibm.com/software/webservers/appserv/community/ IBM WebSphere Application Server Community Edition] 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.
Line 23: Line 23:
 
*There is also an express version of [http://www-01.ibm.com/software/data/db2/express/ IBM DB2 Express C 9.5] available
 
*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 CE</font>===
 
===<font color="green">Install WebSphere CE</font>===
I installed the latest [http://www-01.ibm.com/software/webservers/appserv/community/ GlassFish V2.1 WebSphere CE build 2.1.0.1 (Sept 2008)] and followed the instructions on that page.
+
I installed the latest [http://www-01.ibm.com/software/webservers/appserv/community/ IBM WebSphere CE build 2.1.0.1 (Sept 2008)] and followed the instructions on that page.
  
 
===Install WebSphere CE Eclipse 3.4 Server Plugin===
 
===Install WebSphere CE Eclipse 3.4 Server Plugin===
Line 29: Line 29:
 
*I selected to download the zip, and treat is a a local update site in eclipse
 
*I selected to download the zip, and treat is a a local update site in eclipse
  
===Validating the GlassFish/Eclipse configuration===
+
===Validating the WebSphereCE/Eclipse configuration===
 +
*Follow the [http://publib.boulder.ibm.com/wasce/V2.1.0/en/quick-start.html quickstart] guide on the IBM website.
 
*In the servers view select ''New | Server''
 
*In the servers view select ''New | Server''
 +
[[Image:Wasce_define_new_server.JPG]]
 +
 
*Use the '''IBM|IBM WASCE v2.1 Server''' plugin when creating a server
 
*Use the '''IBM|IBM WASCE v2.1 Server''' plugin when creating a server
 +
*Note: WebSphere CE 2.1 is only certified in Java SE 1.5 (However JDK 1.6 runtime support is available) - You may use a SUN 1.6 JRE and continue
 +
[[Image:Wasce_server_plugin_supports_jse5.JPG]]
 +
 
*Start the server to test the plugin
 
*Start the server to test the plugin
**You should see the following message when running http://127.0.0.1:8080
+
**You should see the following messages when running http://127.0.0.1:8080 on either a 1.5 or 1.6 JRE.
 +
<pre>
 +
Booting Geronimo Kernel (in Java 1.5.0_14)...
 +
Startup completed in 54.065s seconds
  
 +
Booting Geronimo Kernel (in Java 1.6.0_04)...
 +
Startup completed in 29.424s seconds
 +
</pre>
  
==WebSphere Configuration Changes==
+
==WebSphere CE Configuration Changes==
 +
WebSphere CE configuration modifications can be done on the admin console http://127.0.0.1:8080/console using the login system:manager
 +
 
 +
Currently working past a deployment blocking issue where both '''Run on Server''' from the Eclipse IDE or a drop of the EAR/WAR into the '''deploy''' directory has failed on both a 1.5 and 1.6 JRE.
 +
 
 +
See
 +
*[http://www-128.ibm.com/developerworks/forums/thread.jspa?threadID=225325 http://www-128.ibm.com/developerworks/forums/thread.jspa?threadID=225325]
 +
*[http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14124192 http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14124192]
 +
*[http://publib.boulder.ibm.com/wasce/V2.1.0/en/deployment-framework.html http://publib.boulder.ibm.com/wasce/V2.1.0/en/deployment-framework.html]
 +
===Run on Server fails with NPE===
 +
[[Image:Run_on_server_fails_with_npe.JPG]]
 +
 
 +
<pre>
 +
!ENTRY org.eclipse.wst.server.core 4 0 2008-09-18 14:07:35.432
 +
!MESSAGE Could not publish to the server.
 +
!STACK 0
 +
java.lang.NullPointerException
 +
at org.apache.geronimo.st.core.internal.DependencyHelper.getEnvironment(DependencyHelper.java:353)
 +
at org.apache.geronimo.st.core.internal.DependencyHelper.reorderModules(DependencyHelper.java:97)
 +
at org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate.publishModules(GeronimoServerBehaviourDelegate.java:216)
 +
at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBehaviourDelegate.java:868)
 +
at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBehaviourDelegate.java:707)
 +
at org.eclipse.wst.server.core.internal.Server.publishImpl(Server.java:2406)
 +
at org.eclipse.wst.server.core.internal.Server$StartJob.run(Server.java:313)
 +
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
 +
</pre>
 +
 
 +
===WAR dropped into deploy directory===
 +
<pre>
 +
13:36:21,972 WARN  [TomcatModuleBuilder] Web application . does not contain a WEB-INF/geronimo-web.xml deployment plan.  This may or may not be a problem, depending on whether you have things like resource references that need to be resolved.  You can also give the deployer a separate deployment plan file on the command line.
 +
</pre>
  
 
==JNDI Datasource Setup==
 
==JNDI Datasource Setup==
Line 49: Line 91:
  
 
==Create J2EE application==
 
==Create J2EE application==
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
 
<pre>
 
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.persistence.core"/>
 
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.persistence.jpa"/>
 
or
 
<classpathentry combineaccessrules="false" kind="src" path="/eclipselink.jar"/>
 
</pre>
 
*After EAR project creation - reference the org.eclipse.peristence.core and jpa projects or include a reference to eclipselink.jar in your EJB/WAR projects.
 
*If you don't reference the eclipselink.* projects then include a classpath reference to persistence.jar and an Oracle (or other Database) JDBC driver jar for your DB.
 
  
 
==Persistence.xml==
 
==Persistence.xml==
Line 106: Line 131:
  
 
==Start Server==
 
==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==
 
==Publish EAR==
Line 114: Line 137:
  
 
===Browser Output===
 
===Browser Output===
 
 
 
 
All of persistence.xml configuration, jpql query example - in progress ......
 
  
  

Latest revision as of 10:18, 8 April 2010

Contents

[edit] EclipseLink JPA Deployed on IBM WebSphere CE 2.1 using Eclipse WTP

  • This tutorial needs to be finished and/or expanded - vote for EclipseLink bug# 308477 if you would like this work to be fast tracked.

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 CE - 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 Community Edition 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.

[edit] 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 - Note 1.5.0_14 comes with the server, IBM WebSphere CE 2.1.0.1

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

[edit] Prerequisites

[edit] Install Eclipse EE

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

[edit] 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

[edit] Install WebSphere CE

I installed the latest IBM WebSphere CE build 2.1.0.1 (Sept 2008) and followed the instructions on that page.

[edit] Install WebSphere CE Eclipse 3.4 Server Plugin

The WebSphere CE server plugin is not shipped by default with Eclipse - you will need to update your Eclipse IDE to pick up the WebSphere CE Eclipse plugin.

  • I selected to download the zip, and treat is a a local update site in eclipse

[edit] Validating the WebSphereCE/Eclipse configuration

  • Follow the quickstart guide on the IBM website.
  • In the servers view select New | Server

Wasce define new server.JPG

  • Use the IBM|IBM WASCE v2.1 Server plugin when creating a server
  • Note: WebSphere CE 2.1 is only certified in Java SE 1.5 (However JDK 1.6 runtime support is available) - You may use a SUN 1.6 JRE and continue

Wasce server plugin supports jse5.JPG

  • Start the server to test the plugin
Booting Geronimo Kernel (in Java 1.5.0_14)...
Startup completed in 54.065s seconds

Booting Geronimo Kernel (in Java 1.6.0_04)...
Startup completed in 29.424s seconds

[edit] WebSphere CE Configuration Changes

WebSphere CE configuration modifications can be done on the admin console http://127.0.0.1:8080/console using the login system:manager

Currently working past a deployment blocking issue where both Run on Server from the Eclipse IDE or a drop of the EAR/WAR into the deploy directory has failed on both a 1.5 and 1.6 JRE.

See

[edit] Run on Server fails with NPE

Run on server fails with npe.JPG

!ENTRY org.eclipse.wst.server.core 4 0 2008-09-18 14:07:35.432
!MESSAGE Could not publish to the server.
!STACK 0
java.lang.NullPointerException
	at org.apache.geronimo.st.core.internal.DependencyHelper.getEnvironment(DependencyHelper.java:353)
	at org.apache.geronimo.st.core.internal.DependencyHelper.reorderModules(DependencyHelper.java:97)
	at org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate.publishModules(GeronimoServerBehaviourDelegate.java:216)
	at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBehaviourDelegate.java:868)
	at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBehaviourDelegate.java:707)
	at org.eclipse.wst.server.core.internal.Server.publishImpl(Server.java:2406)
	at org.eclipse.wst.server.core.internal.Server$StartJob.run(Server.java:313)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

[edit] WAR dropped into deploy directory

13:36:21,972 WARN  [TomcatModuleBuilder] Web application . does not contain a WEB-INF/geronimo-web.xml deployment plan.  This may or may not be a problem, depending on whether you have things like resource references that need to be resolved.  You can also give the deployer a separate deployment plan file on the command line.

[edit] JNDI Datasource Setup

[edit] Global Scoped Datasource Setup

[edit] Persistence JAR location

[edit] EclipseLink JAR location

[edit] JDBC JAR location

[edit] Create J2EE application

[edit] Persistence.xml

The WebSphere CE server is defined as generic "WebSphere"

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

[edit] Start Server

[edit] Publish EAR

[edit] Perform CRUD operations: JPQL insert and query

[edit] Browser Output

[edit] References


Originated on build 20080916 - Michael O'Brien