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

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

m (Tutorial Design)
m (Replacing page with '=EclipseLink JPA Deployed on Oracle WebLogic 10.3/11g using Eclipse WTP=')
Line 1: Line 1:
 
=EclipseLink JPA Deployed on Oracle WebLogic 10.3/11g using Eclipse WTP=
 
=EclipseLink JPA Deployed on Oracle WebLogic 10.3/11g using Eclipse WTP=
 
If you want to get a small JPA / EJB 3 based web application running quickly on WebLogic - 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 needed to run EclipseLink inside WebLogic 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.
 
 
==Tutorial Source==
 
The EAR, EJB and WEB Eclipse project source for this EclipseLink WebLogic tutorial is available online at the following locations.  These 3 projects must be imported along with the jpa core eclipselink project.
 
 
*Checkout the following 3 projects together from $trunk/examples.
 
**''org.eclipse.persistence.example.jpa.server.weblogic.enterpriseEAR''
 
**''org.eclipse.persistence.example.jpa.server.weblogic.enterpriseEJB''
 
**''org.eclipse.persistence.example.jpa.server.weblogic.enterpriseWeb''
 
 
* EclipseLink source via SVN committer access
 
svn+ssh://user@eclipse/svnroot/rt/org.eclipse.persistence/trunk
 
 
* EclipseLink source via SVN anonymous access
 
svn://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk
 
 
The following link will put you at the root of the SVN tree using the online version of subclipse.
 
 
http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.weblogic.enterpriseEAR
 
 
http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.weblogic.enterpriseEJB
 
 
http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.weblogic.enterpriseWeb
 
 
And the DDL generation J2SE JPA application used to populate the database schema.
 
 
http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.common.ddlgen
 
 
==Development Environment==
 
'''Hardware:''' Windows Vista SP1, HP Core2Quad, 2.4Ghz, 3Gb Ram
 
 
'''Software:''' [http://phoenix.eclipse.org/packages Eclipse IDE for Java EE 3.4 M5 Ganymede] (Feb 2008) with all 5 packages (DTP 1.6, EMF 2.4, GEF 3.4, WTP 3.0, XSD 2.4), Oracle 11g DB 11.1.0.6.0, [http://java.sun.com/javase/downloads/?intcmp=1281 SUN Java JDK 1.6.0_07], [http://www.oracle.com/technology/software/products/ias/htdocs/wls_main.html?rssid=rss_otn_soft WebLogic 10.3.3.1]
 
 
This example will run fine with Eclipse 3.3 EE and any Database that EclipseLink supports.
 
 
==Prerequisites==
 
===<font color="green">Install Eclipse EE</font>===
 
*I installed a clean version of Eclipse Ganymede 3.4 RC2 EE edition with all of WTP 3.0
 
*I modified the [http://wiki.eclipse.org/EclipseLink/Development/Testing/Prereq#Recommended_eclipse.ini_settings_for_EclipseLink eclipse.ini] file parameters
 
 
===<font color="green">Install a Database</font>===
 
*In this example I am using Oracle 11g, the table schemas have already been created manually and all entity java classes have been generated using the Eclipse DALI tool.
 
 
===<font color="green">Install Oracle WebLogic Server</font>===
 
*Oracle WebLogic Server 10.3 on OTN [http://www.oracle.com/technology/software/products/ias/htdocs/wls_main.html?rssid=rss_otn_soft Oracle WebLogic Server 10.3]
 
*WEBLOGIC_HOME=C:/bea/wlserver_10.3
 
 
===<font color="green">Install Oracle WebLogic Server Tools for Eclipse</font>===
 
*Eclipse 3.3/3.4 EE does not come with the WebLogic server configurations out of the box, however you can add it from eclipse with the following steps, you must in order to pick up the 10.x server plugins.
 
* In Eclipse [[EclipseLink/Examples/JPA/WebLogic_Web_Tutorial#Create_server_in_Eclipse|goto the link "Download additional server adapters"]]
 
 
* Note: The bea-wls-tools-2.0.2 plugin works only up to Eclipse 3.4 Ganymede M5 (not the later RC(n) versions) - this [https://dev2devclub.bea.com/updates/wls-tools/ plugin site] has been deprecated.
 
 
==WebLogic configuration Changes==
 
===BEA WebLogic 10.0 MP1 Specific configuration===
 
If you must use the older version of WebLogic 10.0.1 then everything in this WebLogic tutorial will run in 10.0 as long as you do the following modifications before deploying the EAR.
 
*remove the 10.3 specific parts of the weblogic-web-app namespace from enterpriseWeb/WebContent/WEB-INF/weblogic.xml
 
*remove the 10.3 specific parts of the weblogic-application namespace from enterpriseEAR/EarContent/META-INF/weblogic-application.xml
 
 
==JNDI Datasource Setup==
 
 
===Global Scoped Datasource Setup===
 
For ease of use, I would recommend that you use a globally defined datasource on your WebLogic server.  This way all your applications can share the same datasource.  The setup is also much simpler and requires only a single line in your container managed persistence.xml file.
 
 
*Note: Your ''<jta-data-source>'' element in persistence.xml must match the ''JNDI Name:'' on the server admin page ''Home >Summary of JDBC Data Sources '' - either prefixed with jdbc/ or not.
 
 
*You may update config.xml directly - not recommended, or use the admin console wizard to create your JNDI datasource.
 
 
====Setting up a Globally Scoped JNDI Datasource on the WebLogic Server Console====
 
*Navigate to http://127.0.0.1:7001/console
 
*Select JDBC | Data Sources
 
*Select new and enter all of the URL, username, password, port, JNDI Name, Name that matches your '''ejbModule/META-INF/persistence.xml''' parameters.
 
<source lang="xml">
 
<jta-data-source>localJTA</jta-data-source> <!-- equal to JNDI Name and optionally Name -->
 
</source>
 
*Name = ''localJTA''
 
*JNDI Name = ''localJTA''
 
*Database Type = ''Oracle''
 
*Database Driver = (default) ''Oracle's Driver (Thin XA) for Intance connections; Versions: 9.0.1,9.2.0,10,11''
 
*Next
 
*Transaction Options = Next
 
*Database Name = ''orcl'' or your database schema name
 
*Host Name = ''127.0.0.1'' or your database IP address
 
*Database User Name = ''scott'' or your database user name
 
*Password = you know it
 
*Next (twice)
 
*Make sure to associate this datasource with your server instance in the last step '''"Targets"'''
 
[[Image:Weblogic_103_admin_jdbc_datasource_target.JPG]]
 
*''Note: after using the admin console - you will need to remove the edit.lok file on your domain before you can do a "run on server" from the Eclipse IDE.''
 
*Select Targets = check ''AdminServer'' or your own domain server
 
*Save
 
 
*wls10n/user_projects/domains/base_domain/config/config.xml will contain the following new entry where OracleDS-nnnn-jdbc.xml will contain all the DB properties parameters.
 
<source lang="xml">
 
<jdbc-system-resource>
 
  <name>OracleDS</name>
 
  <target>AdminServer</target>
 
  <descriptor-file-name>jdbc/OracleDS-0429-jdbc.xml</descriptor-file-name>
 
</jdbc-system-resource>
 
</source>
 
 
===Application Scoped Datasource Setup===
 
If you require the use of an application scoped/deployed datasource, please refer to the following documentation on [[EclipseLink/Examples/JPA/WLS_AppScoped_DataSource|how to setup and reference an application scoped datasource on WebLogic 10.3]].
 
 
When using JPA you will only require 1 of the 5 custom weblogic descriptors - weblogic-application.xml described below.
 
 
[http://download.oracle.com/docs/cd/E11035_01/wls100/jdbc_admin/packagedjdbc.html#wp1053852 Weblogic JDBC documentation]
 
 
Your oracle-jdbc.xml will require an Application scope.
 
<source lang="xml">
 
  <jdbc-data-source-params>
 
    <jndi-name>appDS</jndi-name>
 
    <scope>Application</scope>
 
</source>
 
 
Your persistence.xml will require both <jta-data-source> and the fully qualified "javax.persistence.jtaDataSource" property defined - override behavior is described in bug# [http://bugs.eclipse.org/246126 246126].
 
<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>appDS</jta-data-source>
 
    <properties>
 
      <property name="javax.persistence.jtaDataSource" value="java:app/jdbc/appDS"/>
 
</source>
 
 
==EclipseLink JAR location==
 
===javax.persistence.jar===
 
*EclipseLink supports JPA 1.0 and JPA 2.0, you will therefore need to verify that the container supports both of these.
 
**Verify that both javax.persistence_*.jar files are in the same directory or higher (modules) as your eclipselink.jar
 
===eclipselink.jar on the Server or EAR?===
 
*It is not recommended that you distribute eclipselink.jar with your EAR application in a production environment. 
 
**Why? One reason is that an application deployed EclipseLink jar will be lower on the server ClassLoader tree and will not be available to other modules or applications higher up due to hierarchical visibility constraints.  However, there may be occasions during '''development''' or '''staging''' that you will want to run a local copy or different version than the one loaded from the modules directory - I have not tested this scenario yet, a test of the 3 use cases will be required.
 
 
===Option 1: Leave shipped module as is - Recommended===
 
====Oracle WebLogic Standalone Server====
 
*EclipseLink now works out of the box in WebLogic 10.3.3.1
 
*As of WebLogic Server 10.3.3.1 the EclipseLink library is shipped in the following location on the server.  You may use this version unless you would like to override the jar with a different version in options 2-4 below
 
**$WEBLOGIC_HOME/modules/org.eclipse.persistence_1.0.0.0_1-1.0.jar
 
**or $WEBLOGIC_HOME/*/patch_jars/org.eclipse.persistence_1*.jar (depending on your patch level)
 
 
====Oracle WebLogic Embedded as part of Oracle Fusion Middleware in JDeveloper====
 
The embedded WebLogic server is treated the same as the standalone except that WEBLOGIC_HOME == MIDDLEWARE_HOME - you will need to keep the second copy used for design-time compilation in the '''jdeveloper'' directory in sync with the modules one.
 
 
See eclipselink.jar in
 
<pre>
 
<weblogic_home>\patch_wls1030\patch_jars
 
or
 
<weblogic_home>\modules
 
</pre>
 
Which should match the design-time jars in
 
<pre><weblogic_home>\jdeveloper\modules\oracle.toplink_11.1.1</pre>
 
 
===Option 2: eclipselink.jar on domain===
 
To get the server to automatically pick up eclipselink.jar during startup - it should be placed off of ''$WEBLOGIC_HOME/samples/domains/wl_server/lib''
 
 
'''Or if you have created your own default user domain put the jar into the following directory'''
 
<pre>$WEBLOGIC_HOME/user_projects/domains/base_domain/lib</pre>
 
 
You will see the following on startup
 
<pre>
 
<Sep 3, 2008 11:22:56 AM EDT> <Notice> <WebLogicServer> <BEA-000395> <Following extensions directory contents added to the end of the classpath:
 
C:\opt\wls103a\user_projects\domains\base_domain\lib\eclipselink.jar;
 
C:\opt\wls103a\wlserver_10.3\platform\lib\p13n\p13n-schemas.jar;
 
C:\opt\wls103a\wlserver_10.3\platform\lib\p13n\p13n_common.jar;
 
C:\opt\wls103a\wlserver_10.3\platform\lib\p13n\p13n_system.jar;
 
C:\opt\wls103a\wlserver_10.3\platform\lib\wlp\netuix_common.jar;
 
C:\opt\wls103a\wlserver_10.3\platform\lib\wlp\netuix_schemas.jar;
 
C:\opt\wls103a\wlserver_10.3\platform\lib\wlp\netuix_system.jar;
 
C:\opt\wls103a\wlserver_10.3\platform\lib\wlp\wsrp-client.jar;
 
C:\opt\wls103a\wlserver_10.3\platform\lib\wlp\wsrp-common.jar>
 
</pre>
 
 
===Option 3: eclipselink.jar specified at startup===
 
If you want to reference eclipselink.jar outside of the WebLogic install then you must modify the startup script that was generated for your domain.
 
 
see $C:\opt\wls103a\user_projects\domains\base_domain\bin\startWebLogic.cmd:85.
 
 
Note: I haven't preserved anything that may already been set on weblogic.ext.dirs - we should append the eclipselink.jar with a path delimiter - however this web application predeploys and runs fine with the following path addition instead of using option 1 above.
 
<pre>
 
set JAVA_OPTIONS=%JAVA_OPTIONS% -Dweblogic.ext.dirs=c:\eclipselink.jar
 
</pre>
 
 
See the updated classpath and predeploy logs
 
<pre>
 
<Sep 3, 2008 11:39:40 AM EDT> <Notice> <WebLogicServer> <BEA-000395> <Following extensions directory contents added to the end of the classpath:
 
C:\eclipselink.jar;
 
C:\opt\wls103a\wlserver_10.3\platform\lib\p13n\p13n-schemas.jar;C:\opt\wls103a\wlserver_10.3;.....C:\opt\wls103a\wlserver_10.3\platform\lib\wlp\wsrp-common.jar>
 
....
 
[EL Finest]: 2008.09.03 11:39:55.497--ServerSession(32263885)--Thread(Thread[Thread-20,5,Pooled Threads])--Begin predeploying Persistence Unit unified; state Initial; factoryCount 0
 
</pre>
 
 
===Option 4: eclipselink.jar on server - not recommended===
 
 
If using multiple domains you may put eclipselink.jar higher in the classloader tree by dropping it into (TBD - test scenario required).
 
 
*Jar additions to ''$WEBLOGIC_HOME/wlserver_10.3/server/lib'' are not automatically picked up by the server.
 
*Jar additions to ''$WEBLOGIC_HOME/user_projects/domains/base_domain/config/lib'' are not automatically picked up by the server and require configuration.
 
 
==JDBC JAR location==
 
Jars for Oracle 11, MySQL 5 and Sybase 5.5/6.0 are off their own directories in
 
<pre>$WEBLOGIC_HOME/wlserver_10.[0|3]/server/ext/jdbc</pre>
 
 
==Create server in Eclipse==
 
*Open the servers view in the Java EE pane
 
*Select the WebLogic 10.3 server that is already defined or downloaded in the update step above.
 
'''New | Server | Oracle | WebLogic 10.3'''.
 
 
[[Image:eclipse_weblogic_server_screen2.jpg]]
 
 
*Or Open the servers view for WebLogic 10.3
 
 
'''New | Server | "Download additional server adapters"''' for the latest 10.3 plugin for Ganymede 3.4
 
 
*Point to the WebLogic runtime directory - usually wlserver_10.3
 
 
[[Image:Eclipse_weblogic_server_103_screen2.jpg]]
 
 
*Point to your domain, either the samples or the default domain '''user_projects\domains\base_domain''' created by the WebLogic tool in the start menu '''WebLogic Server 10gR3 | tools | Configuration Wizard '''
 
[[Image:Eclipse_weblogic_server_103_screen3_domain.jpg]]
 
 
==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 WAR project.
 
*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 - You will need to put this JDBC driver jar in your WebLogic ''/domains/wl_server/lib'' directory as well.
 
 
===UML Data Model===
 
The following single entity ''Cell'' has a @ManyToMany bidirectional relationship to itself.
 
 
[[Image:Eclipselink_server_jee_jpa_examples_datamodel.gif]]
 
 
====Tutorial Design====
 
The goal of the tutorial is to demonstrate a quick start end-to-end deployment on a specific application server of an EclipseLink JPA application.
 
To accomplish this...
 
* The web framework is a simple servlet so we avoid container specific issues around JSF implementation.
 
* The data model is very simple (@ManyToMany) - as the other tutorials get into more advanced JPA entity concepts and annoations
 
* The entitymanager is container managed where possible by injection
 
* The schema is generated by DDL generation in a separate common [http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.common.ddlgen application managed SE app].
 
* The application context name is standard across servers
 
* The datasource is globally defined (by the user) on the server - with the only configuration setting being the jta-data-source element in persistence.xml
 
 
====DDL/Schema Generation====
 
*The database schema for this example can be automatically generated using the DDL generation capability of EclipseLink (normally only used by development or for demos).  The following project in SVN can be run as an application managed stand-alone JPA project that has ddl-generation turned on in the persistence.xml.
 
* http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.common.ddlgen
 
*Note: DDL Generation is not possible on a container managed entity manager connected to a JTA datasource - hence the use of a separate project that is server agnostic and sharable by all the [[EclipseLink/Examples/JPA|JPA Web application tutorials]] in this section of the Wiki.
 
 
==Persistence.xml==
 
===JTA Datasource===
 
*JTA : Put persistence.xml beside your JPA entities in ''yourProjectEJB/ejbModule/META-INF'' 
 
*Note: Your ''<jta-data-source>'' or ''<non-jta-data-source>'' element in persistence.xml must match the '''JNDI Name:''' on the server admin page ''Home >Summary of JDBC Data Sources '' - either prefixed with jdbc/ or not.
 
 
 
<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="unifiedWebLogic" transaction-type="JTA">
 
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
 
    <jta-data-source>OracleDS</jta-data-source>       
 
    <non-jta-data-source>OracleDS</non-jta-data-source>
 
    <properties>
 
      <property name="eclipselink.target-server" value="WebLogic_10"/>
 
      <property name="eclipselink.logging.level" value="FINEST"/>
 
    </properties>
 
  </persistence-unit>
 
</persistence>
 
</source>
 
===RESOURCE_LOCAL Datasource===
 
*RESOURCE_LOCAL : non-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="unifiedWebLogic" transaction-type="RESOURCE_LOCAL">
 
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
 
    <properties>
 
      <property name="eclipselink.target-server" value="WebLogic_10"/>
 
      <property name="eclipselink.logging.level" value="FINEST"/>
 
      <property name="eclipselink.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
 
      <property name="eclipselink.jdbc.platform" value="org.eclipse.persistence.platform.database.oracle.OraclePlatform"/>
 
      <property name="eclipselink.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
 
      <property name="eclipselink.jdbc.user" value="user"/>
 
      <property name="eclipselink.jdbc.password" value="pw"/>
 
    </properties>
 
  </persistence-unit>
 
</persistence>
 
</source>
 
 
==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".
 
===Troubleshooting===
 
If you get the following JTA exception then your [[EclipseLink/Examples/JPA/WebLogic_Web_Tutorial#JNDI_Datasource_Setup|globally defined JTA datasource]] has not been setup above on the WebLogic server yet - add the JDBC data source and restart the server.
 
 
<pre>
 
Exception [EclipseLink-28010] (Eclipse Persistence Services - 1.1.0 (Build 20081203)): org.eclipse.persistence.exceptions.EntityManagerSetupException
 
Exception Description: PersistenceUnitInfo example has transactionType JTA, but doesnt have jtaDataSource.
 
at org.eclipse.persistence.exceptions.EntityManagerSetupException.jtaPersistenceUnitInfoMissingJtaDataSource(EntityManagerSetupException.java:154)
 
</pre>
 
 
Note: Whenever you use the admin console on WebLogic, before you attempt to restart the server using the Eclipse IDE server plugin - delete the edit.lok file on the root of your '''base_domain'''.
 
 
==Publish EAR==
 
*Publishing to WebLogic 10 is very simple (you don't require an IDE like Eclipse), once the server is setup you can just drop/remove an EAR in the autodeploy directory to domains/wl_server/autodeploy an application.  Or use Eclipse to debug via the 5005 port if the server is managed through WTP.
 
*Eclipse WTP will take care of copying the EAR file to the live deploy directory when you either [re-publish] or modify any files while the server is running.
 
*You may also use any combination of running the WebLogic server yourself in run or debug mode and using eclipse to publish EAR changes.
 
 
*Depending on your application you will see the following predeploy/deploy logs after running [start server]
 
**In your console window you will see one process both for the server and the deploy target.
 
<pre>
 
starting weblogic with Java version:
 
BEA JRockit(R) (build R27.3.1-1_CR344434-89345-1.5.0_11-20070925-1628-windows-ia32, compiled mode)
 
[EL Finest]: 2008.05.21 15:54:03.251--ServerSession(7692289)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Begin predeploying Persistence Unit unifiedWebLogic; state Initial; factoryCount 0
 
[EL Config]: 2008.05.21 15:54:04.048--ServerSession(7692289)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--The alias name for the entity class [class org.eclipse.persistence.example.unified.business.StatLabel] is being defaulted to: StatLabel.
 
[EL Finer]: 2008.05.21 15:54:04.188--ServerSession(7692289)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Class [org.eclipse.persistence.example.unified.business.StatLabel] registered to be processed by weaver.
 
<May 21, 2008 3:54:11 PM EDT> <Notice> <WebLogicServer> <BEA-000331> <Started WebLogic Admin Server "examplesServer" for domain "wl_server" running in Development Mode>
 
</pre>
 
 
==Perform a JPQL query==
 
*At this time you can exercise your application in a browser by requesting a JPQL query - notice the use of the JTA datasource.
 
** http://127.0.0.1:7001/enterprise/FrontController
 
** This url command gets a container managed EntityManager via @EJB injection of the ApplicationServiceLocal Stateless Session Bean which contains an EM reference.
 
<source lang="java">
 
public class FrontController extends HttpServlet implements Servlet {
 
@EJB(beanName="ApplicationService")
 
public ApplicationServiceLocal applicationService;
 
...
 
 
@Local
 
public interface ApplicationServiceLocal {
 
...
 
 
@Local
 
@Stateless
 
public class ApplicationService implements ApplicationServiceLocal {
 
@PersistenceContext(unitName="example")
 
private EntityManager entityManager;
 
...
 
 
</source>
 
===Console Output===
 
<pre>
 
[EL Finest]: 2008.05.21 15:58:30.112--ServerSession(7692289)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Weaved persistence (PersistenceEntity) [org.eclipse.persistence.example.unified.business.StatLabel].
 
[EL Info]: 2008.05.21 15:58:30.798--ServerSession(7692289)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--EclipseLink, version: Eclipse Persistence Services - 1.0 (Build SNAPSHOT - 20080507)
 
[EL Info]: 2008.05.21 15:58:30.798--ServerSession(7692289)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Server: WebLogic Server 10.0 MP1  Thu Oct 18 20:17:44 EDT 2007 1005184
 
[EL Fine]: 2008.05.21 15:58:31.985--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Detected Vendor platform: org.eclipse.persistence.platform.database.oracle.Oracle10Platform
 
[EL Config]: 2008.05.21 15:58:32.016--ServerSession(7692289)--Connection(8272442)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--connecting(DatabaseLogin( platform=>Oracle10Platform user name=> "stat" datasource URL=> "jdbc:oracle:thin:@localhost:1521:orcl"
 
[EL Finest]: 2008.05.21 15:58:33.061--UnitOfWork(9354744)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Execute query ReadAllQuery(org.eclipse.persistence.example.unified.business.StatLabel)
 
[EL Fine]: 2008.05.21 15:58:33.093--ServerSession(7692289)--Connection(8318645)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--SELECT ID, DATE_STAMP FROM STAT_LABEL WHERE (ID < ?)
 
bind => [200]
 
[EL Finest]: 2008.05.21 15:58:34.544--UnitOfWork(9354744)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Register the existing object org.eclipse.persistence.example.unified.business.StatLabel@96976d
 
 
</pre>
 
 
===Browser Output===
 
====One Persistence Unit====
 
The following screen capture of this quickstart JEE WebLogic JPA application shows a visual representation of the entities persisted to the Oracle database using the EclipseLink JPA implementation on Oracle WebLogic Server 10.3
 
[[Image:eclipselink_example_jpa_weblogic_web_jpql_action_cap2.jpg]]
 
 
====Two Persistence Units====
 
This section details a use case where we need to use two different persistence units defined in the same persistence.xml file where the datasources are on different physical database servers.
 
 
The following capture is from a persistence.xml mapping file on the EJB.jar that has two persistence units where each point to the same Entity name "Cell" but the entities are in different packages.  This will test any possible naming conflict between the entities.
 
 
[[Image:Two_pu_with_same_entities_diff_packages.JPG]]
 
 
=====persistence.xml with three persistence units=====
 
<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="exampleDuplicate" transaction-type="JTA">
 
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
 
        <jta-data-source>remoteJTA</jta-data-source>
 
        <class>org.eclipse.persistence.example.jpa.server.entity.Cell</class>
 
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
 
        <properties>
 
            <property name="eclipselink.target-server" value="WebLogic_10"/>
 
            <property name="eclipselink.logging.level" value="FINEST"/>
 
            <!-- property name="eclipselink.orm.validate.schema" value="false"/-->           
 
        </properties>     
 
    </persistence-unit>
 
    <persistence-unit name="example" transaction-type="JTA">
 
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
 
        <jta-data-source>localJTA</jta-data-source>
 
        <class>org.eclipse.persistence.example.jpa.server.business.Cell</class>
 
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
 
        <properties>
 
            <property name="eclipselink.target-server" value="WebLogic_10"/>
 
            <property name="eclipselink.logging.level" value="FINEST"/>
 
            <!-- property name="eclipselink.orm.validate.schema" value="false"/-->           
 
        </properties>     
 
    </persistence-unit>
 
    <persistence-unit name="exampleLocal" transaction-type="RESOURCE_LOCAL">
 
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
 
        <class>org.eclipse.persistence.example.jpa.server.business.Cell</class>
 
        <exclude-unlisted-classes>true</exclude-unlisted-classes>       
 
        <properties>
 
            <property name="eclipselink.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
 
            <property name="eclipselink.jdbc.platform" value="org.eclipse.persistence.platform.database.oracle.OraclePlatform"/>
 
            <property name="eclipselink.jdbc.url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"/>
 
            <property name="eclipselink.jdbc.user" value="scott"/>
 
            <property name="eclipselink.jdbc.password" value="pw"/>
 
            <!-- property name="eclipselink.logging.logger" value="JavaLogger"/-->
 
            <!-- turn on table generation only to initialize db and then disable the two elements below -->
 
            <!-- property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
 
            <property name="eclipselink.ddl-generation.output-mode" value="database"/-->               
 
        </properties>     
 
    </persistence-unit>
 
</persistence>
 
</source>
 
 
 
 
In the case of using both persistence units I get 2 sets of 4 logs = 8 for the 4 connections to the 2 datasources
 
The two datasources in my case are Oracle11g (remoteJTA) and Oracle10g (localJTA) - both using the same 11g driver - so it is easier to tell them apart in the logs.
 
 
<pre>
 
EL Example: enterprise: Object: org.eclipse.persistence.example.jpa.server.entity.Cell@26145598( id: 1 state: null left: null right: null parent: HashSet@234560 references: HashSet@234560)
 
</pre>
 
 
When i use the exampleDuplicate persistence unit i get a login for the first Oracle 10g based datasource  (remoteJTA)
 
 
<pre>
 
EL Config: 2008.12.15 15:43:56.419--ServerSession(3303389)--Connection(28810575)--Thread(Thread[)--Connected: jdbc:oracle:thin:@127.0.0.1:1521:orcl
 
User: SCOTT
 
Database: Oracle Version: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
 
With the Partitioning, OLAP, Data Mining and Real Application Testing options
 
Driver: Oracle JDBC driver Version: 11.1.0.7.0-Production
 
EL Config: 2008.12.15 15:43:56.419--ServerSession(3303389)--Connection(28892307)--Thread(Thread[)--connecting(DatabaseLogin(
 
platform=>Oracle10Platform
 
user name=> ""
 
connector=>JNDIConnector datasource name=>null
 
))
 
</pre>
 
 
and the persist call for the first set of entities in the first persistence unit
 
 
<pre>
 
EL Example: enterprise: ApplicationService persisting: org.eclipse.persistence.example.jpa.server.business.Cell@13251215( id: null state: null left: null right: null parent: HashSet@18981093 references: HashSet@18981093) on EM: org.eclipse.persistence.internal.jpa.EntityManagerImpl@1a7ed8f> later when I use the other example persistence unit i get a login for the second datasource
 
</pre>
 
 
Later when using the Oracle 11g based datasource (localJTA)
 
 
<pre>
 
EL Config: 2008.12.15 15:43:56.966--ServerSession(25279766)--Connection(6794127)--Thread(Thread[)--Connected: jdbc:oracle:thin:@10.156.53.19:1521:orcl
 
User: SCOTT
 
Database: Oracle Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
 
With the Partitioning, OLAP and Data Mining options
 
Driver: Oracle JDBC driver Version: 11.1.0.7.0-Production
 
EL Config: 2008.12.15 15:43:56.966--ServerSession(25279766)--Connection(3176465)--Thread(Thread[)--connecting(DatabaseLogin(
 
platform=>Oracle10Platform
 
user name=> ""
 
connector=>JNDIConnector datasource name=>null
 
))
 
</pre>
 
 
And the persist call for the second set of entities in the second persistence unit
 
 
<pre>
 
EL Example: enterprise: ApplicationService2 persisting: org.eclipse.persistence.example.jpa.server.entity.Cell@20979305( id: null state: null left: null right: null parent: HashSet@14247956 references: HashSet@14247956) on EM: org.eclipse.persistence.internal.jpa.EntityManagerImpl@14bf56d
 
</pre>
 
 
The servlet client uses two stateless session beans for entitymanager access
 
 
<source lang="java">
 
public class FrontController extends HttpServlet implements Servlet {
 
    @EJB(beanName="ApplicationService")
 
    public ApplicationServiceLocal applicationService;
 
    @EJB(beanName="ApplicationService2")
 
    public ApplicationServiceLocal2 applicationService2;
 
...
 
 
    // Later I must fully reference my entities because in this case they have the same class name in different packages
 
    List<org.eclipse.persistence.example.jpa.server.business.Cell> rowsList = (List<org.eclipse.persistence.example.jpa.server.business.Cell>)getApplicationService().query("select object(e) from Cell e");
 
    List<org.eclipse.persistence.example.jpa.server.entity.Cell> rowsList2 = (List<org.eclipse.persistence.example.jpa.server.entity.Cell>)getApplicationService2().query("select object(e) from Cell e");
 
</source>
 
 
Each entitymanager is injected into the stateless session beans
 
 
<source lang="java">
 
package org.eclipse.persistence.example.jpa.server.entity;
 
@Local @Stateless
 
public class ApplicationService implements ApplicationServiceLocal {
 
@PersistenceContext(unitName="example", type=PersistenceContextType.TRANSACTION)
 
private EntityManager entityManager;
 
</source>
 
 
<source lang="java">
 
package org.eclipse.persistence.example.jpa.server.entity;
 
@Local @Stateless
 
public class ApplicationService2 implements ApplicationServiceLocal2 {
 
@PersistenceContext(unitName="exampleDuplicate", type=PersistenceContextType.TRANSACTION)
 
private EntityManager entityManager;
 
</source>
 
 
 
Both versions of the Cell entity (in different packages but with the same schema on different databases) are located on the ejb.jar along with the session beans
 
 
<source lang="java">
 
package org.eclipse.persistence.example.jpa.server.entity;
 
@Entity
 
@Table(name="EL_CELL")
 
public class Cell implements Serializable {
 
</source>
 
 
<source lang="java">
 
package org.eclipse.persistence.example.jpa.server.business;
 
@Entity
 
@Table(name="EL_CELL")
 
public class Cell implements Serializable {
 
</source>
 
 
==Troubleshooting==
 
*1) If you get a "domain locked" popup error in eclipse when publishing your ear - delete the following lock file in your server domain
 
**$WEBLOGIC_HOME\user_projects\domains\base_domain\edit.lok
 
*2) If you get a WST error popup in Eclipse when you try to export your EAR - it is most likely due to an inconsistent workspace (a file is missing/modified on the disc but has not been refreshed to the Eclipse IDE) - try refreshing the 3 projects here first.
 
*3) If you have changed your entity schema between deployments and you find some weird behavior where you are seeing both your new entities and the old entities (without the schema changes) - this is most likely due to a cached entity on the server that has not been updated for some reason - usually when you combine both manual deployment to the autodeploy directory and "run-on-server" from the Eclipse IDE.
 
**The workaround is to clear non-session entities from the cache under
 
**user_projects\domains\base_domain\servers\AdminServer\cache\EJBCompilerCache
 
 
===Password Encryption Error===
 
For application defined datasources, if you get the following '''invalid pad byte''' exception when deploying your EAR to WebLogic 10.3.3.1 then check that you are using the latest ''AES'' encryption instead of ''3DES''.  You can regenerate your encrypted password by creating a temporary globally defined datasource and viewing the *jdbc.xml file generated on your domain config directory.
 
<pre>
 
Feb 20, 2009 11:46:01 AM EST> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID '1235148360979' for task '20'. Error is: 'com.rsa.jsafe.JSAFE_PaddingException: Could not perform unpadding: invalid pad byte.'
 
com.rsa.jsafe.JSAFE_PaddingException: Could not perform unpadding: invalid pad byte.
 
at com.rsa.jsafe.JA_PKCS5Padding.a(Unknown Source)
 
at com.rsa.jsafe.JG_BlockCipher.decryptFinal(Unknown Source)
 
at weblogic.security.internal.encryption.JSafeEncryptionServiceImpl.decryptBytes(JSafeEncryptionServiceImpl.java:113)
 
at weblogic.security.internal.encryption.JSafeEncryptionServiceImpl.decryptString(JSafeEncryptionServiceImpl.java:173)
 
at weblogic.security.internal.encryption.ClearOrEncryptedService.decrypt(ClearOrEncryptedService.java:96)
 
</pre>
 
<source lang="xml">
 
Don't use
 
    <password-encrypted>{3DES}...=</password-encrypted> <!-- before load 12 -->
 
Use
 
    <password-encrypted>{AES}...=</password-encrypted> <!-- after load 12 -->
 
</source>
 
 
==EJB bean JNDI client lookup without injection==
 
The following steps need to be done so that a non-servlet client (J2SE) can lookup an instance of the stateless session bean deployed on WebLogic by this application.
 
 
===weblogic-ejb-jar.xml===
 
TBD
 
==References==
 
*See [http://wiki.eclipse.org/Integrating_EclipseLink_with_an_Application_Server_(ELUG) Integrating EclipseLink with an Application Server in the ELUG]
 
*See [[EclipseLink/UserGuide/Developing_JPA_Projects_%28ELUG%29|Developing JPA Projects]] in the EclipseLink User's Guide.
 
* [http://wiki.eclipse.org/EclipseLink/Examples/JMX/MBeans_WebLogic JMX MBean Tutorial for WebLogic]
 
*http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.weblogic.enterpriseEAR
 
*http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.weblogic.enterpriseEJB
 
*http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.weblogic.enterpriseWeb
 
* [[EclipseLink/Development/Architecture/EclipseLink|EclipseLink Architecture and UML Diagrams]]
 
 
==Oracle WebLogic Server Documentation Links==
 
* [http://www.oracle.com/technology/software/products/ias/htdocs/wls_main.html?rssid=rss_otn_soft Oracle WebLogic Server Downloads]
 
* [http://edocs.bea.com/wls/docs103/index.html Oracle WebLogic Server 10.3 Documentation]
 
* [http://edocs.bea.com/wls/docs103/ejb30/annotations.html WebLogic EJB 3.0 Metadata Annotations Reference]
 
* [http://download.oracle.com/docs/cd/E11035_01/wls100/admin_ref/weblogicServer.html#wp1008482 WebLogic Server command line options -including how to patch]
 

Revision as of 16:39, 24 March 2009

EclipseLink JPA Deployed on Oracle WebLogic 10.3/11g using Eclipse WTP

Back to the top