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

(EclipseLink JPA Deployed on OC4J using Eclipse WTP)
(EclipseLink JPA Deployed on OC4J using Eclipse WTP)
 
Line 1: Line 1:
==EclipseLink JPA Deployed on OC4J using Eclipse WTP==
 
  
Note: This page started on 20080409 is in edit progress for 72 hours until 20080412
 
 
 
This example details how to use Eclipse to run/debug a J2EE web application servlet using EclipseLink JPA as the persistence provider.  Examples where the presentation/controller layer use JSF and Spring are pending or available here.
 
 
Tested Environment:
 
Hardware: Windows Vista SP1, HP Core2Quad, 2.4Ghz, 3Gb Ram
 
Software: Eclipse 3.4 M5 Ganymede (Feb 2008) with all 5 WTP packages (DTP 1.6, EMF 2.4, GEF 3.4, WTP 3.0, XSD 2.4)
 
Oracle 11g DB 11.1.0.6.0
 
Java JDK 1.5.0_11
 
OC4J 11.1.1.0.0 Preview 3
 
 
This example will run fine with Eclipse 3.3 and any DB that EclipseLink supports.
 
 
Prerequisites
 
 
Install Eclipse
 
I installed a clean version of Eclipse Ganymede M5 with all of WTP 3.0
 
 
Install a DB like Oracle (10g/11g/XE)
 
In this example I have created all table schemas manually and generated all annotated entities using the Eclipse Dali tool.
 
 
Install OC4J11
 
http://www.oracle.com/technology/products/ias/toplink/preview/index.html
 
 
Here I installed to the following directory.
 
C:\opt\oc4j11samba
 
Where OC4J_HOME=C:/opt/oc4j11samba/j2ee/home
 
 
Edit oc4j11 config
 
$OC4J_HOME/config/data-sources.xml
 
  <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>
 
 
 
 
Place eclipselink.jar inside OC4J
 
The eclipselink.jar should be placed as noted by config/server.xml in the directory $OC4J_HOME/applib
 
  <!-- Global application libraries -->
 
  <shared-library name="global.libraries" version="1.0" library-compatible="true">
 
    <code-source path="../applib"/>
 
  </shared-library>
 
 
Create server in Eclipse
 
Open the servers view
 
New | Server | Oracle | Oracle OC4J Standalone Server 10.1.3.1 (it is ok to use this one for 11.1.1)
 
I had to change my admin user from oc4jadmin to fmwadmin.
 
 
 
Create J2EE application
 
Check out the 3 example projects or create your own J2EE Enterprise Application.
 
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
 
 
<classpathentry combineaccessrules="false" kind="src" path="/eclipselink.core"/>
 
<classpathentry combineaccessrules="false" kind="src" path="/eclipselink.jpa"/>
 
 
 
After creation, reference eclipselink.core and eclipselink.jpa or include a reference to eclipselink.jar
 
 
Persistence.xml
 
Put persistence.xml in projectWeb\src\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="statJPATopLinkJ2EE" transaction-type="RESOURCE_LOCAL">
 
      <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
 
        <non-jta-data-source>jdbc/OracleDS</non-jta-data-source>
 
        <class>org.eclipse.persistence.example.navigation.business.StatClass</class>
 
… other entity classes
 
        <properties>
 
            <property name="eclipselink.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
 
            <property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.oracle.OraclePlatform"/>           
 
            <property name="eclipselink.logging.level" value="FINEST"/>
 
        </properties>     
 
    </persistence-unit>
 
</persistence>
 
 
 
 
Start server
 
Select the Ear (or the War) and Run on Server.
 
The first run may not start the server, here you start the server and then Run on Server.
 
 
Publish EAR
 
In the predeploy of the War you should see weaving messages for your entities if logs are set to FINEST in persistence.xml
 
 
Depending on your application you will see
 
 
Action> Start Server
 
 
In your console window you will see two processes one for the server and the second for the deploy target.
 
 
Oracle OC4J SA Server 11.1.1.0.0 localhost [Generic Server]
 
C:\jdk1.5.0\bin\javaw.exe (Apr 9, 2008 9:06:19 AM)
 
<terminated>jpaELTestEAR module publisher [Ant Build]
 
<terminated, exit value: 0>C:\jdk1.5.0\bin\javaw.exe (Apr 9, 2008 9:06:36 AM)
 
 
If you click on the deploy target you will see the deploy logs...
 
 
 
Buildfile: C:\eclipse34\plugins\org.eclipse.jst.server.generic.oc4j_1.5.105.v20071217\buildfiles\oracle.10.1.3.xml
 
check.skip.ear.deploy:
 
deploy.j2ee.ear:
 
package.module.ear:
 
      [jar] Building jar: C:\opt\oc4j11samba\j2ee\home\applications\jpaELTestEAR.ear
 
[oracle:deploy] Deploying application jpaELTestEAR.
 
[oracle:deploy] 08/04/09 09:06:39 Notification ==>Uploading file jpaELTestEAR.ear ...
 
[oracle:deploy] 08/04/09 09:06:39 Notification ==>Application Deployer for jpaELTestEAR STARTS.
 
...
 
[oracle:deploy] 08/04/09 09:06:41 Notification ==>Application Deployer for jpaELTestEAR COMPLETES. Operation time: 2155 msecs
 
[oracle:deploy] Application deployer for jpaELTestEAR COMPLETES.
 
BUILD SUCCESSFUL
 
Total time: 5 seconds
 
 
If you click on the server console you will see 08/04/09 09:06:21 WARNING: Bulk-load class 'oracle.j2ee.naming.ldap.ucp.SASSLSocketFactory' not found in /C:/opt/oc4j11samba/j2ee/home/lib/oc4j-internal.jar (from <code-source> in META-INF/boot.xml in C:\opt\oc4j11samba\j2ee\home\oc4j.jar)
 
08/04/09 09:06:21 WARNING: Bulk-load class 'oracle.security.idm.mad.ECIDProvider' not found in oc4j:11.1.1.0.0
 
Apr 9, 2008 9:06:23 AM oracle.j2ee.xml.XMLMessages warningException
 
WARNING: Exception Encountered
 
08/04/09 09:06:25 JMS server will listen on port 9127.
 
08/04/09 09:06:26 oracle.j2ee.jms JMSServer startup complete.
 
08/04/09 09:06:26 SEVERE: AbstractInfo.getAnnotation oracle.webservices.annotations.async.AsyncWebService cannot be found in the given classpath.
 
08/04/09 09:06:26 SEVERE: AbstractInfo.getAnnotation oracle.webservices.annotations.async.AsyncWebService cannot be found in the given classpath.
 
08/04/09 09:06:27 Don't know how to map non-serializable type: interface javax.management.j2ee.statistics.Stats to Open MBean Type.
 
08/04/09 09:06:28 WARNING: J2EE JNDI-00002
 
08/04/09 09:06:28 WARNING: No javax.jms.ConnectionFactory found at null
 
08/04/09 09:06:29 Oracle Containers for J2EE 11g (11.1.1.0.0)  initialized.
 
08/04/09 09:06:39 Application Deployer for jpaELTestEAR STARTS.
 
...
 
08/04/09 09:06:39 Started application : jpaELTestEAR
 
08/04/09 09:06:39 Binding jpaELTestWeb web-module for application jpaELTestEAR to site default-web-site under context root jpaELTest
 
[EPS Finest]: 2008.04.09 09:06:39.893--ServerSession(23543153)--Thread(Thread[DeployerRunnable Thread for jpaELTestEAR,9,SystemThreadGroup])--Begin predeploying Persistence Unit statJPATopLinkJ2EE; state Initial; factoryCount 0
 
...
 
[EPS Finer]: 2008.04.09 09:06:39.924--ServerSession(23543153)--Thread(Thread[DeployerRunnable Thread for jpaELTestEAR,9,SystemThreadGroup])--Searching for default mapping file in file:/C:/opt/oc4j11samba/j2ee/home/applications/jpaELTestEAR/jpaELTestWeb/WEB-INF/classes/
 
[EPS Finer]: 2008.04.09 09:06:39.940--ServerSession(23543153)--Thread(Thread[DeployerRunnable Thread for jpaELTestEAR,9,SystemThreadGroup])--Found a default mapping file at file:/C:/opt/oc4j11samba/j2ee/home/applications/jpaELTestEAR/jpaELTestWeb/WEB-INF/classes/META-INF/orm.xml for root URL file:/C:/opt/oc4j11samba/j2ee/home/applications/jpaELTestEAR/jpaELTestWeb/WEB-INF/classes/
 
...
 
[EPS Finer]: 2008.04.09 09:06:40.783--ServerSession(23543153)--Thread(Thread[DeployerRunnable Thread for jpaELTestEAR,9,SystemThreadGroup])--Class [org.eclipse.persistence.example.navigation.business.StatClass] registered to be processed by weaver.
 
...
 
[EPS Finest]: 2008.04.09 09:06:40.783--ServerSession(23543153)--Thread(Thread[DeployerRunnable Thread for jpaELTestEAR,9,SystemThreadGroup])--End predeploying Persistence Unit statJPATopLinkJ2EE; state Predeployed; factoryCount 1
 
[EPS Finest]: 2008.04.09 09:06:41.033--ServerSession(23543153)--Thread(Thread[DeployerRunnable Thread for jpaELTestEAR,9,SystemThreadGroup])--Begin weaver class transformer processing class [org/eclipse/persistence/example/navigation/business/StatClass].
 
[EPS Finest]: 2008.04.09 09:06:41.079--ServerSession(23543153)--Thread(Thread[DeployerRunnable Thread for jpaELTestEAR,9,SystemThreadGroup])--End weaver class transformer processing class [org/eclipse/persistence/example/navigation/business/StatClass].
 
...
 
08/04/09 09:06:41 Binding web application(s) to site default-web-site ends...
 
08/04/09 09:06:41 Application Deployer for jpaELTestEAR COMPLETES. Operation time: 2155 msecs
 
 
 
At this time you can initialize your application in a browser - notice the use of the non-jta datasource>
 
http://127.0.0.1:8888/jpaELTest/FrontController?action=init
 
 
This url command will initialize the EntityManager
 
    emf = Persistence.createEntityManagerFactory(puName);
 
    entityManager = emf.createEntityManager();
 
 
 
Console Output>
 
 
08/04/09 09:19:29 Action: init
 
[EPS Finest]: 2008.04.09 09:19:29.634--ServerSession(2059288)--Thread(Thread[HTTPThreadGroup-1,9,HTTPThreadGroup])--Begin deploying Persistence Unit statJPATopLinkJ2EE; state Predeployed; factoryCount 2
 
[EPS Warning]: 2008.04.09 09:19:29.868--ServerSession(2059288)--Thread(Thread[HTTPThreadGroup-1,9,HTTPThreadGroup])--PersistenceUnitInfo statJPATopLinkJ2EE has transactionType RESOURCE_LOCAL and therefore jtaDataSource will be ignored
 
[EPS Info]: 2008.04.09 09:19:29.884--ServerSession(2059288)--Thread(Thread[HTTPThreadGroup-1,9,HTTPThreadGroup])--EclipseLink, version: Eclipse Persistence Services - 1.0 (Build SNAPSHOT - 20080403)
 
[EPS Config]: 2008.04.09 09:19:30.289--ServerSession(2059288)--Connection(17254324)--Thread(Thread[HTTPThreadGroup-1,9,HTTPThreadGroup])--connecting(DatabaseLogin(
 
platform=>OraclePlatform
 
user name=> "stat"
 
connector=>JNDIConnector datasource name=>null
 
))
 
[EPS Config]: 2008.04.09 09:19:30.289--ServerSession(2059288)--Connection(16022259)--Thread(Thread[HTTPThreadGroup-1,9,HTTPThreadGroup])--Connected: jdbc:oracle:thin:@//127.0.0.1:1521/orcl
 
User: STAT
 
Database: Oracle  Version: Oracle Database 11g Release 11.1.0.0.0 - Production
 
Driver: Oracle JDBC driver  Version: 11.1.0.6.0-Production+
 
[EPS Finest]: 2008.04.09 09:19:30.289--ServerSession(2059288)--Thread(Thread[HTTPThreadGroup-1,9,HTTPThreadGroup])--sequencing connected, state is Preallocation_NoTransaction_State
 
[EPS Finest]: 2008.04.09 09:19:30.289--ServerSession(2059288)--Thread(Thread[HTTPThreadGroup-1,9,HTTPThreadGroup])--sequence STAT_CLASS_SEQ_GENERATOR: preallocation size 25
 
[EPS Info]: 2008.04.09 09:19:30.336--ServerSession(2059288)--Thread(Thread[HTTPThreadGroup-1,9,HTTPThreadGroup])--file:/C:/opt/oc4j11samba/j2ee/home/applications/jpaELTestEAR/jpaELTestWeb/WEB-INF/classes/-statJPATopLinkJ2EE login successful
 
[EPS Finest]: 2008.04.09 09:19:30.336--ServerSession(2059288)--Thread(Thread[HTTPThreadGroup-1,9,HTTPThreadGroup])--End deploying Persistence Unit statJPATopLinkJ2EE; state Deployed; factoryCount 2
 
 
Exercise your application in a browser>
 
http://127.0.0.1:8888/jpaELTest/FrontController?action=query&jpql=select%20object(e)%20from%20StatClass%20e%20where%20e.id<100
 
 
Browser Output>
 
 
action: query
 
JPQL: select object(e) from StatClass e where e.id<100
 
99 Results
 
1 org.eclipse.persistence.example.navigation.business.StatClass@15c0102
 

Latest revision as of 15:22, 9 April 2008

Back to the top