Jump to: navigation, search

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

m (Oracle WebLogic Server Documentation Links)
m (Oracle WebLogic Server Documentation Links)
Line 1,263: Line 1,263:
* [http://download.oracle.com/docs/cd/E12840_01/wls/docs103/programming/classloading.html WebLogic ClassLoaders]
* [http://download.oracle.com/docs/cd/E12840_01/wls/docs103/programming/classloading.html WebLogic ClassLoaders]
* [http://download.oracle.com/docs/cd/E12840_01/wls/docs103/client/jarbuilder.html Standalone client for Remote Stateless Session EJB beans on WebLogic servers - instructions for eradicating CNFE for WebLogic implementations of javax.ejb, javax.transaction and javax.naming Java EE API]
* [http://download.oracle.com/docs/cd/E12840_01/wls/docs103/client/jarbuilder.html Standalone client for Remote Stateless Session EJB beans on WebLogic servers - instructions for eradicating CNFE for WebLogic implementations of javax.ejb, javax.transaction and javax.naming Java EE API]
* Section [http://docs.oracle.com/cd/E23943_01/doc.1111/e25034/tlandwls.htm#BABFFDEA 2.3.3:  Task 3: Update the Version of EclipseLink in WebLogic Server] at OTN is partially based on this original EclipseLink tutorial.
* Section [http://docs.oracle.com/cd/E23943_01/doc.1111/e25034/tlandwls.htm#BABFFDEA 2.3.3:  Task 3: Update the Version of EclipseLink in WebLogic Server] at OTN is partially based on [http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/weblogic#DI_1.1:_Alternative_3:_Application_Level_Shared_Library_-_In_Use this] original EclipseLink tutorial.

Revision as of 07:51, 31 March 2012


EclipseLink JPA Deployed on Oracle WebLogic using Eclipse WTP

Alternate Distributed JPA Application using a WebLogic Central Server

  • See the Distributed JPA Application case study on how JPA works and deals with Optimistic lock exception scenarios using Java EE 6 API elements - specifically as a single persistence unit used by the distributed application as an alternative to using a shared L2 cache. This tutorial also demostrates use of alternate client and presentation frameworks that include any number of concurrent distributed Java SE clients that get, process and submit work units to the central server via a remote stateless session bean instance.

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 4 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
    • org.eclipse.persistence.example.jpa.server.entities
  • EclipseLink source via SVN committer access


  • EclipseLink source via SVN anonymous access


The following link will put you at the root of the SVN tree using the online version of subclipse.





And the DDL generation J2SE JPA application used to populate the database schema.


Development Environment

Hardware: Windows 7 64-bit, Dell XPS436 Corei7 920 , 2.7Ghz, 12Gb Ram, Raptor HD

Software: Eclipse IDE for Java EE 3.5 SR-2 Galileo (Sept 2009), Derby, SUN Java JDK 1.6.0_18, WebLogic 10.3

This example will run fine with Eclipse 3.4 EE and any Database that EclipseLink supports.


Install Eclipse EE

Install a Database

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

Install Oracle WebLogic Server

  • Oracle WebLogic Server 11gR1 with integrated Oracle Coherence and Oracle Enterprise Pack for Eclipse (OEPE) on OTN Oracle WebLogic Server 10.3
  • WEBLOGIC_HOME=C:/bea/wlserver_10.3
  • Either apply the appropriate patch using Smart Update or download your own EclipseLink libraries.

Install Oracle WebLogic Server Tools for Eclipse

  • You can unzip the plugins zip and copy it over your eclipse install. After you will see the new WebLogic server plugins when creating a new server.

Oepe1115 create server 11gR1ps3.jpg

  • See outstanding 288275 if you are installing on an older Eclipse Ganymede 3.4 IDE.

Oracle WebLogic Server 10.3.5

  • WebLogic 10.3.5 was released on 15 May 2011.

Oracle WebLogic Server 10.3.4

  • For Eclipse 3.6 Helios integration with WebLogic 10.3.4 try to use at least version 1.7.0_20110127 of Oracle WebLogic Server Tools
  • See bug # 334468 for tracking info.
  • The version of EclipseLink shipped with WebLogic is Eclipse Persistence Services - 2.1.2.v20101206-r8635


  • Weblogic1034 install cap.jpg
Java EE 6 API in this Tutorial
  • I will be addressing the following Java EE 6 API's
    • Java Persistence 2.0 (JSR 317) - with patch
    • JAX-RS (RESTful Web Services) 1.1 (JSR 311)
    • JSF (Java Server Faces) 2.0 (JSR 314)
  • I will not be officially using the following Java EE 6 API's as part of this tutorial

Oracle WebLogic Server

  • Vote for bug# 310849 if you would like specific configuration info expanded.
  • Oracle Enterprise Pack for Eclipse 11gR1 Patch Set 2 comes preconfigured with WebLogic if you selected the combined download.
  • EclipseLink is upgraded from 1.2 to 2.0.
  • Follow this tutorial on using the OEPE tool.
  • However, you must delete and recreate the supplied Eclipse IDE server instance to get past the following error message.

Oepe 10330 default server error.JPG

Cannot load DeploymentManager for Runtime[Oracle WebLogic Server 11gR1 PatchSet 2, Oracle WebLogic Server 11gR1 PatchSet 2, C:/opt/wls10330/wlserver_10.3, RuntimeType[com.bea.weblogic1033, Oracle WebLogic Server 11gR1 PatchSet 2]]
The server is invalid. Error occurred reading server credential. If the domain was recreated, the server instance in Eclipse must also be recreated.
  • The version of EclipseLink shipped with WebLogic is Eclipse Persistence Services - 2.0.2.v20100323-r68726872

Oracle WebLogic Server

Oracle WebLogic Server

  • The 10.3.1 download on OTN includes OEPE tools
  • 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 do this in order to pick up the 10.x server plugins.
  • In Eclipse goto the link "Download additional server adapters"
  • Select Oracle WebLogic Server Tools

Weblogic server tools server plugin in eclipse.JPG

  • For 10.3.3 installs (use the patchset 2 plugin)
  • For 10.3.2 installs (use the patchset 1 plugin)

Oracle weblogic 11g server plugins.JPG

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

JVM and EclipseLink Logging

  • All JVM and EclipseLink logs will be visible on the WebLogic domain console output window. This window will either be the Java process that runs as a CMD window when WebLogic is launched as a separate process or service, or it will be the server log window when running WebLogic from Eclipse.
  • If you would like to see the logs in the base_domain log files then you will need to check the following property that is not set by default from the admin console web application.
    • Home >Summary of Deployments >base_domain >Summary of Servers >AdminServer >Summary of Servers >AdminServer

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
  • 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.
<jta-data-source>localJTA</jta-data-source> <!-- equal to JNDI Name and optionally Name -->
  • 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 = 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"

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.
Testing the DataSource in the Admin Console

You may verify that your datasource and connection pool are working by testing the datasource from the admin console web page.

  • Navigate to Home >Summary of JDBC Data Sources >localJTA >Roles >localJTA | Configuration | Connection Pool
  • Expand the Advanced tab
  • Check Test Connections On Reserve
  • Save
  • Goto Monitoring | Testing - select your datasource and click Test Data Source
  • You should see Test of localJTA on server AdminServer was successful

Derby JTA Datasource Setup

Weblogic derby jta datasource setup.JPG

Application Scoped Datasource Setup

If you require the use of an application scoped/deployed datasource, please refer to the following documentation on 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.

Weblogic JDBC documentation

Your oracle-jdbc.xml will require an Application scope.


Your persistence.xml will require both <jta-data-source> and the fully qualified "javax.persistence.jtaDataSource" property defined - override behavior is described in bug# 246126.

<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">
      <property name="javax.persistence.jtaDataSource" value="java:app/jdbc/appDS"/>

EclipseLink JAR location

Upgrade EclipseLink Module on WebLogic - org.eclipse.persistence_1.0.0.0_major_minor.jar

  • For advanced users: navigate to your 'modules directory and overwrite the existing eclipselink jar
  • In my case WebLogic ships with EclipseLink 2.0 - to upgrade to EclipseLink 2.1 - I overwrite the following jar
    • C:\opt\wls10330\modules\org.eclipse.persistence_1.0.0.0_2-0.jar

Other ways to upgrade EclipseLink on WebLogic

  • There are at least 6 (six) ways to run EclipeLink on WebLogic, the details are below.
  • Issues to keep in mind are...
      • How high do you want the EclipseLink libraries in the classpath tree (remember that the JPA specification jar must be at or above whereever you decide to run EclipseLink)?
      • What version do you wish to run? The shipped version or the latest snapshot version?


  • EclipseLink supports JPA 1.0 in 1.1 and JPA 2.0 in the 2.0 EclipseLink jar, you will therefore need to verify that the container supports one or 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 EclipseLink shipped on modules directory - Recommended for

  • This option requires no work - you will run with the shipped version of EclipseLink (currently 1.2 as of 20090909).
  • If you wish to override this version of EclipseLink either replace these jars with a leter version (Container and application managed persistence units) or push your own shared library with your EAR via the wls:prefer-application-packages element in weblogic-application.xml (Application managed persistence units only).

Option 2: Apply Smart Update Patch - Recommended for

  • This option is available to commercial TopLink customers.

Oracle WebLogic Standalone Server

Summary of relevant EE, JPA and native JARS after Smart Update
  • As a result of the 9J3A patch update (via the MANIFEST of weblogic_ext_patch.jar)
  • C:\opt\wls1030_otn_200906\patch_wls1030\patch_jars\eclipselink.jar
  • C:\opt\wls1030_otn_200906\patch_wls1030\patch_jars\toplink.jar
  • C:\opt\wls1030_otn_200906\patch_wls1030\patch_jars\commonj.sdo_2.1.0.jar
  • From original 10.3.0 install
    • C:\opt\wls1030_otn_200906\modules\javax.persistence_1.0.0.0_1-0.jar
    • C:\opt\wls1030_otn_200906\modules\javax.ejb_3.0.1.jar
    • C:\opt\wls1030_otn_200906\modules\javax.servlet_1.0.0.0_2-5.jar
    • C:\opt\wls1030_otn_200906\modules\javax.transaction_1.0.0.0_1-1.jar
Applying the EclipseLink WebLogic Patch
  • To add EclipseLink to your WebLogic 10.3 server - run the Smart Update tool
    • You will see the following screen after login

WebLogic Smart Update main screen.JPG

  • Select the latest patch or 9J3A:Patch to add Oracle TopLink 11g(, including EclipseLink 1.0.1 CR 379710,383032
  • Apply this patch 9J3A in Manage Patches
  • The installed patch will place the EclipseLink library 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-5 below
  • $WEBLOGIC_HOME/patch_wls1030/patch_jars/eclipselink.jar
EclipseLink position on the WebLogic Classpath

The 9J3A patch will place the EclipseLink jar below weblogic.jar at the end of the classpath via the MANIFEST-only jar with path references below...


This weblogic_ext_patch.jar is empty but contains path references to the patch jars below...

Class-Path: ../../../patch_jars/commonj.sdo_2.1.0.jar ../../../patch_jars/eclipselink.jar ../../../patch_jars/toplink.jar
  • I recommend that the patch jars be left as-is unless you require the jars at your $Domain/lib level.
    • For example, after applying patch 9J3A, creating a JNDI datasource via the console and running the EAR from this tutorial on WebLogic from Eclipse EE 3.5 without modifications, I see the following...
<Jun 15, 2009 2:32:38 PM EDT> <Notice> <WebLogicServer> <BEA-000395> <Following extensions directory contents added to the end of the classpath:
[EL Finest]: 2009.06.15 14:33:00.500--ServerSession(9124497)--Thread(Thread[[STANDBY] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Begin predeploying Persistence Unit example; state Initial; factoryCount 0
[EL Fine]: 2009.06.15 14:57:05.937--ServerSession(9124497)--Connection(1906643)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--SELECT ID, TSEQ, STATE, RIGHT_ID FROM EL_CELL WHERE (RIGHT_ID = ?)
	bind => [4]

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


Which should match the design-time jars in


Option 3: 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


You will see the following on startup

<Sep 3, 2008 11:22:56 AM EDT> <Notice> <WebLogicServer> <BEA-000395> <Following extensions directory contents added to the end of the classpath:

Option 4: eclipselink.jar specified at startup

Note: This procedure will add your custom jars to the end of the server classpath - the jars in the modules directory will still override ones here.

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.

set JAVA_OPTIONS=%JAVA_OPTIONS% -Dweblogic.ext.dirs=c:\eclipselink.jar

See the updated classpath and predeploy logs

<Sep 3, 2008 11:39:40 AM EDT> <Notice> <WebLogicServer> <BEA-000395> <Following extensions directory contents added to the end of the classpath:
[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

Option 5: eclipselink.jar on server - not recommended

If using multiple domains you may put eclipselink.jar higher in the classloader tree by referencing it above weblogic.jar in commEnv.cmd.

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

Option 6: Override and Download EclipseLink Libraries from Eclipse.org

Another option is to manage your own version of EclipseLink (If for example you would like to try an unreleased latest snapshot). The downloaded jars should be placed in the modules directory off the install root.

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

  • This option is available for developers that wish to run the latest snapshot builds.
  • Get the following eclipselink.jar and javax.persistence*.jar from http://www.eclipselink.org ready for your EclipseLink shared library.

JSR-317 JPA 2.0 Support

  • Update: 20110115: WebLogic was released to OTN - all WebLogic related content - see 334468
  • EclipseLink 1.2 and 2.0+ fully implement the JPA 2.0 specification via enhancement # 248291 and are the RI for the GlassFish V3 Java EE 6 server.
  • See the following design page details on WebLogic Server (up to 10.3.3) support for JPA 2.0 which is no longer required in WebLogic 10.3.4

JDBC JAR location

Jars for Oracle 11, MySQL 5 and Sybase 5.5/6.0 are off their own directories in


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.

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

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

Eclipse weblogic server 103 screen3 domain.jpg

Create J2EE application

Either checkout the 3 source projects attached to this tutorial or 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
	<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.persistence.core"/>
	<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.persistence.jpa"/>
	<classpathentry combineaccessrules="false" kind="src" path="/eclipselink.jar"/>
  • After EAR project creation - reference the org.eclipse.peristence.core and jpa projects or include a reference to eclipselink.jar in your EJB project and reference the EJB project from 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.

Application.xml WAR EJB.jar Module order can cause ClassLoader issues

EJB module with @PersistenceContext Injection should be first

  • See bug # 323148 where the EJB module containing a persistence unit must preceed any WAR modules that use it.
  • Apparently for certain so far JSF based EAR applications the order of the modules in application.xml must be EJB.jar then the WAR. However in the case of this tutorial application either order works fine - specifically weaving is OK.
  • The exact details of this issue must be determined and posted.
  • This application order is recommended so we do not encounter any issues if the app is switched to use JSF in the future
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" id="Application_ID" version="5">
  • In either case we currently weave the Entity ok.
Cell  (id=13447)   
    _persistence_fetchGroup    null   
    _persistence_left_vh    ValueHolder  (id=13451)   
        isCoordinatedWithProperty    false   
        isNewlyWeavedValueHolder    true   
        value    null   
    _persistence_listener    null   
    _persistence_primaryKey    null   
    _persistence_right_vh    ValueHolder  (id=13452)   
        isCoordinatedWithProperty    false   
        isNewlyWeavedValueHolder    true   
        value    null   
    _persistence_session    null   
    _persistence_shouldRefreshFetchGroup    false   
    id    null   
    left    null   
    peers    HashSet<E>  (id=13453)   
    references    HashSet<E>  (id=13454)   
    right    null    

UML Data Model

The following single entity Cell has a @ManyToMany bidirectional relationship to itself.

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


JTA Datasource

  • JTA is the default transaction-type when deployed in an EE container.
  • 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.

<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="example" transaction-type="JTA">
      <property name="eclipselink.target-server" value="WebLogic_10"/>
      <property name="eclipselink.logging.level" value="FINEST"/>


  • RESOURCE_LOCAL is the default transaction-type when running the persistence unit as a standalone SE Java project.
  • Note: JTA is the default transaction-type when deployed in an EE container.
  • RESOURCE_LOCAL : non-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="example" transaction-type="RESOURCE_LOCAL">
      <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"/>

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".
  • Note: Stopping the WebLogic server in the CMD window (if it is not launched via the OEPE (Oracle Enterprise Pack for Eclipse plugin) will also require that the java.exe process be closed as well (because we are only closing the connection to the server)( - look for the one around 580Mb (64-bit) or 290 (32-bit) - or you will get a .lok exists error when rerunning the tests. You may still need to manually remove the .lok sentinel from your profile anyway in this case. Bottom line is to keep everything in Eclipse.


  • If you get the following JTA exception then your globally defined JTA datasource has not been setup above on the WebLogic server yet - add the JDBC data source and restart the server.
Exception [EclipseLink-28010] ***: 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)
  • Alternatively, If you are expecting to run as transaction-type="RESOURCE_LOCAL" then note that in the server's EE container the persistence unit will default to JTA in the absence of a specified transaction-type persistence unit attribute.

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.

Debugging JTA on the WebLogic Server container

  • Launch the server from Eclipse with the following additional options
    • -Dweblogic.debug.DebugJTA2PC=true and -Dweblogic.debug.DebugJTAXA=true

Debugging on WebLogic Server requires disabling the default 30 second transaction timeout

  • - launch admin console at
  • - change Domain Configuration | Services | JTA | Timeout Seconds: (from 30 to 2^30 (the normal 2147483647 max will throw a -1 int exception currently))

Publish EAR

  • Publishing to WebLogic 10.3 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.
starting weblogic with Java version:
BEA JRockit(R) ***, 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> 

Perform a JPQL query using a Stateless EJB Session Bean injected on a Servlet Controller

  • At this time you can exercise your application in a browser by requesting a JPQL query - notice the use of the JTA datasource.
public class FrontController extends HttpServlet implements Servlet {
	public ApplicationServiceLocal applicationService;
public interface ApplicationServiceLocal {
public class ApplicationService implements ApplicationServiceLocal {
	private EntityManager entityManager;
    public boolean insert(Object class1) {
        try {

Alternate JNDI lookup of Injected EntityManager on a Stateless Session Bean

  • This method is an alternative to using @PersistenceContext injection of the EntityManager directly on the field. Here we inject it at the Entity level and reference it with a JNDI lookup.
  • Note: This code will only run on an EE container.
@PersistenceContext(name="ApplicationService", unitName="example", type=PersistenceContextType.TRANSACTION)
public class ApplicationService implements ApplicationServiceLocal {
    SessionContext sessionContext;
    private EntityManager entityManager;
    public boolean insert(Object class1) {
        try {
    public EntityManager getEntityManager() {
        if(null == entityManager) {
            try {
                entityManager = (EntityManager) sessionContext.lookup("ApplicationService");
            } catch (Exception e) {
        return entityManager;

Console Output

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

Browser Output

One Persistence Unit

The following screen capture of this quickstart Java EE 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 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.

Two pu with same entities diff packages.JPG

persistence.xml with three persistence units

<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">
            <property name="eclipselink.target-server" value="WebLogic_10"/>
            <property name="eclipselink.logging.level" value="FINEST"/>
            <!-- property name="eclipselink.orm.validate.schema" value="false"/-->            
    <persistence-unit name="example" transaction-type="JTA">
            <property name="eclipselink.target-server" value="WebLogic_10"/>
            <property name="eclipselink.logging.level" value="FINEST"/>
            <!-- property name="eclipselink.orm.validate.schema" value="false"/-->            
    <persistence-unit name="exampleLocal" transaction-type="RESOURCE_LOCAL">
            <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:@"/>
            <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"/-->                

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.

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)

When i use the exampleDuplicate persistence unit i get a login for the first Oracle 10g based datasource (remoteJTA)

EL Config: 2008.12.15 15:43:56.419--ServerSession(3303389)--Connection(28810575)--Thread(Thread[)--Connected: jdbc:oracle:thin:@
Database: Oracle Version: Oracle Database 11g Enterprise Edition Release - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Driver: Oracle JDBC driver Version:
EL Config: 2008.12.15 15:43:56.419--ServerSession(3303389)--Connection(28892307)--Thread(Thread[)--connecting(DatabaseLogin(
user name=> ""
connector=>JNDIConnector datasource name=>null

and the persist call for the first set of entities in the first persistence unit

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

Later when using the Oracle 11g based datasource (localJTA)

EL Config: 2008.12.15 15:43:56.966--ServerSession(25279766)--Connection(6794127)--Thread(Thread[)--Connected: jdbc:oracle:thin:@
Database: Oracle Version: Oracle Database 10g Enterprise Edition Release - Production
With the Partitioning, OLAP and Data Mining options
Driver: Oracle JDBC driver Version:
EL Config: 2008.12.15 15:43:56.966--ServerSession(25279766)--Connection(3176465)--Thread(Thread[)--connecting(DatabaseLogin(
user name=> ""
connector=>JNDIConnector datasource name=>null

And the persist call for the second set of entities in the second persistence unit

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

The servlet client uses two stateless session beans for entitymanager access

public class FrontController extends HttpServlet implements Servlet {
    public ApplicationServiceLocal applicationService;
    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");

Each entitymanager is injected into the stateless session beans

package org.eclipse.persistence.example.jpa.server.entity;
@Local @Stateless
public class ApplicationService implements ApplicationServiceLocal {
	@PersistenceContext(unitName="example", type=PersistenceContextType.TRANSACTION)	
	private EntityManager entityManager;
package org.eclipse.persistence.example.jpa.server.entity;
@Local @Stateless
public class ApplicationService2 implements ApplicationServiceLocal2 {
	@PersistenceContext(unitName="exampleDuplicate", type=PersistenceContextType.TRANSACTION)	
	private EntityManager entityManager;

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

package org.eclipse.persistence.example.jpa.server.entity;
public class Cell implements Serializable {
package org.eclipse.persistence.example.jpa.server.business;
public class Cell implements Serializable {

Deploying a Secure Enterprise Application on WebLogic

  • In this section we will be describe the steps for getting a secure web application running in a EAR using @PersistenceContext injection on a standard @Stateless @Local session bean that is @EJB injected on a servlet.

WebLogic Server Preparation

Enabling Security

  • 0) The security policy is already set for us - just keep a backup of the original
    • -Djava.security.policy=%WL_HOME%\server\lib\weblogic.policy
  • 1) Turn on the Security Manager in WebLogic
    • $WebLogic_home\user_projects\domains\base_domain\bin\startWebLogic.cmd
      • set JAVA_OPTIONS=%JAVA_OPTIONS% -Djava.security.manager
  • 2) Enable the EclipseLink property eclipselink.security.usedoprivileged
    • $WebLogic_home\user_projects\domains\base_domain\bin\startWebLogic.cmd
      • set JAVA_OPTIONS=%JAVA_OPTIONS% -Declipselink.security.usedoprivileged=true
    • There seems to be some confusion about whether to use = or === - I have used a single =.
  • 3) Grant permissions to the localJTA datasource JDBC jar files.
// localJTA
grant codeBase "file:C:/opt/wls10340rc11/wlserver_10.3/common/derby/lib/-" {
  permission java.net.SocketPermission "", "connect,resolve";
  • Without this you will see the following unrelated to EclipseLink permissions exception
    • <12-Jan-2011 11:43:01 o'clock AM VET> <Warning> <JDBC> <BEA-001129> <Received exception while creating connection for pool "localJTA": access denied (java.net.SocketPermission connect,resolve)>
  • 4) According to http://wiki.eclipse.org/Integrating_EclipseLink_with_an_Application_Server_(ELUG)#Granting_Permissions_for_Java_EE_Application_Deployment we need to grant access to the EclipseLink module as well
  • This step may be optional - as I predeploy the persistence unit fine without it
    • [EL Finest]: 2011-01-12 12:50:47.014--ServerSession(24567153)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Begin predeploying Persistence Unit example; session file:/C:/view_w36a/examples/org.eclipse.persistence.example.jpa.server.weblogic.enterpriseEJB/build/classes/_example; state Initial; factoryCount 0
    • $WebLogic_home/modules/org.eclipse.persistence_1.0.0.0_2-x.jar
grant codeBase "file:C:\opt\wls10340rc11\modules/org.eclipse.persistence_1.0.0.0_2-1.jar" {
    permission java.security.AllPermission;
  • 5) Grant specific access to the WAR and the EJB jar that provides the SSB proxy
grant codeBase "file:C:/opt/wls---/user_projects/domains/base_domain/servers/AdminServer/cache/EJBCompilerCache/-" {
  permission java.security.AllPermission;

Unmodified WebLogic Server

  • The following permissions exception involving the new JTA datasource occurs even before we deploy any ears. This resource java.net.SocketPermission connect,resolve must be granted permissions and is unrelated to EclipseLink deployment.
    • modules unchanged
      • javax.persistence_1.0.0.0_1-0-2.jar
      • javax.persistence_1.0.0.0_2-0-0.jar
      • org.eclipse.persistence_1.0.0.0_2-1.jar
      • $WebLogic_home\user_projects\domains\base_domain\bin\startWebLogic.cmd
      • $WebLogic_home\wlserver_10.3\server\lib\weblogic.policy
      • C:\view_w36a\examples\org.eclipse.persistence.example.jpa.server.weblogic.enterpriseEJB\ejbModule\META-INF\weblogic-ejb-jar.xml
<12-Jan-2011 11:43:01 o'clock AM VET> <Warning> <JDBC> <BEA-001129> <Received exception while creating connection for pool "localJTA": access denied (java.net.SocketPermission connect,resolve)> 
<12-Jan-2011 11:43:02 o'clock AM VET> <Error> <Deployer> <BEA-149205> <Failed to initialize the application 'localJTA' due to error weblogic.application.ModuleException: .
	at weblogic.jdbc.module.JDBCModule.prepare(JDBCModule.java:302)
	at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:199)
	at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:517)
	at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
	at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:159)
	Truncated. see log file for complete stacktrace
Caused By: weblogic.common.ResourceException: access denied (java.net.SocketPermission connect,resolve)
	at weblogic.jdbc.common.internal.XAConnectionEnvFactory.makeConnection(XAConnectionEnvFactory.java:494)
	at weblogic.jdbc.common.internal.XAConnectionEnvFactory.createResource(XAConnectionEnvFactory.java:177)
	at weblogic.common.resourcepool.ResourcePoolImpl.makeResources(ResourcePoolImpl.java:1249)
	at weblogic.common.resourcepool.ResourcePoolImpl.makeResources(ResourcePoolImpl.java:1166)
	at weblogic.common.resourcepool.ResourcePoolImpl.start(ResourcePoolImpl.java:249)


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

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)

EJB bean JNDI client lookup without injection

See http://forums.oracle.com/forums/thread.jspa?threadID=2159122&tstart=0

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.


This wlfullclient.jar is generated with all the libraries an SE application needs that would normally be provided to an EE container app out of the box. In the case of WebLogic this client jar is generated at design time. In the case of GlassFish the equivilant gf-client.jar is provided as a manifest only jar that references the EE libraries by relative path.


public class Node implements NodeRemote, NodeLocal {

Host SE client

package org.eclipse.persistence.example.distributed;
import java.rmi.ConnectException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import javax.ejb.EJBException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import org.eclipse.persistence.example.distributed.NodeRemote;
 * This class tests RMI connections to multiple WebLogic servers running on 
 * remote JVM's.  It is intended for experimental concurrency investigations only.
 * Note: for non-EE/ejb/web contexts (SE) use wlfullclient.jar generated from
 * $WLS_INSTALL\wlserver_10.3\server\lib>java -jar wljarbuilder.jar
 * 20110106: refactor for generic remote connections
 * @author mfobrien 20100916
public class Host {
    /** RMI server key name - does not need to resolve under DNS */
    public static String serverDNS[] = {"beowulf5","beowulf6", "x-pc2"};
    /** RMI t3 URL */
    public static String serverT3[] = {"t3://","t3://", "t3://1x.x.x.x:7001"};    private int numberServers = serverDNS.length;
    /** list of server names from above arrays */
    private List<String> serverNames = new ArrayList<String>();
    /** Input context map hashtable entries - For JNDI we are forced to use Hashtable instead of HashMap*/
    private Map<String, Hashtable<String, String>> contextHashtableMap   = new HashMap<String, Hashtable<String, String>>();
    /** output cached context maps for each remote server */
    private Map<String, Context> rmiCachedContextMap                     = new HashMap<String, Context>();
    /** $Proxy remote objects */
    private Map<String, NodeRemote> remoteObjects                        = new HashMap<String, NodeRemote>();
    /** remote propagation value */
    private Map<String, Integer> stateToSet                              = new HashMap<String, Integer>();
    /** How many processors are available (real + hyperthreaded) */
    private Map<String, Integer> availableProcessors                     = new HashMap<String, Integer>();
    /** whether the node is accepting requests or not */
    private Map<String, Boolean> nodeUnavailable                         = new HashMap<String, Boolean>();
    /** map of t3 protocol URLs */
    private Map<String, String>  serverIPMap                             = new HashMap<String, String>();
    // verify that all EE libraries available via http://download.oracle.com/docs/cd/E12840_01/wls/docs103/client/jarbuilder.html
    private static final String CONTEXT_FACTORY_NAME = "weblogic.jndi.WLInitialContextFactory";
    private static final String SESSION_BEAN_REMOTE_NAME = "ejb/Node#org.eclipse.persistence.example.distributed.NodeRemote"; 
    //private String sessionBeanRemoteName = "java:comp/env/ejb/Node"; // EE only
    //private String sessionBeanRemoteName = "org_eclipse_persistence_example_distributed_ClientEARorg_eclipse_persistence_example_distributed_ClientEJB_jarNode_Home" ;
    public Host() {
        // initialize state
        for(int i=0;i<numberServers;i++) {
            // For each server add the name key and corresponding RMI URL
            serverIPMap.put(serverDNS[i], serverT3[i]);
            nodeUnavailable.put(serverDNS[i], false);
            availableProcessors.put(serverDNS[i], 0);
            Hashtable<String, String> aTable =  new Hashtable<String, String>();
            aTable.put(Context.PROVIDER_URL, serverT3[i]);
    public void connect() {
        //System.out.println("Available Processors on this System: " + availableProcessors);
         * Setup and connect to RMI Objects
        try {            
            // Establish RMI connections to the session beans
            for(String aServer : serverNames) {
                Context aContext = null;
                try {
                    aContext = new InitialContext(contextHashtableMap.get(aServer));
                    rmiCachedContextMap.put(aServer, aContext);
                    System.out.println("Context for " + aServer + " : " + aContext);
                    // For qualified name look for weblogic log "EJB Deployed EJB with JNDI name"
                    Object aRemoteReference = aContext.lookup(SESSION_BEAN_REMOTE_NAME);        
                    System.out.println("Remote Object: " + aRemoteReference);
                    // narrow the $proxy remote bean
                    NodeRemote aNode = (NodeRemote) PortableRemoteObject.narrow(aRemoteReference, NodeRemote.class);
                    remoteObjects.put(aServer, aNode);
                    System.out.println("Narrowed Session Bean: " + aNode);        
                    // initialize state list
                    stateToSet.put(aServer, new Integer(0));
                } catch (Exception ce) {
                    // server down throws a javax.naming.CommunicationException inside a java.net.ConnectException
                    // mark the current node as down, clear the flag in 5 min
                    nodeUnavailable.put(aServer, true);
            NodeRemote aNode;
            StringBuffer aBuffer = new StringBuffer();           
            // Endlessly generate RMI requests
            for(;;) {
                // Send messages to entire grid in parallel
                for(String remoteServer : remoteObjects.keySet()) {
                    aNode = remoteObjects.get(remoteServer);
                    // increment server's pending state
                    stateToSet.put(remoteServer, stateToSet.get(remoteServer).intValue() + 1);
                    if(!nodeUnavailable.get(remoteServer)) {
                        try {
                            // Issue: One JVM halt will affect the entire distributed app.
                            // don't let a node failure halt the host
                            aNode.setState(stateToSet.get(remoteServer)); // this remote call can throw an EJBException wrapping a java.rmi.ConnectException
                            aBuffer = new StringBuffer("State from: ");
                            aBuffer.append(" = ");
                        } catch (EJBException e) {
                            //  weblogic.transaction.internal.TimedOutException: Transaction timed out after 29 seconds
                            // or
                            // EJBException wrapping a java.rmi.ConnectException if the server is not running
                            // mark the current node as down, clear the flag in 5 min
                            nodeUnavailable.put(remoteServer, true);
        } catch (Exception e) {
    public Map<String, Hashtable<String, String>> getContextMap() {        return contextHashtableMap;    }
    public void setContextMap(Map<String, Hashtable<String, String>> contextMap) {        this.contextHashtableMap = contextMap;    }
    public Map<String, Context> getRmiContextMap() {        return rmiCachedContextMap;    }
    public void setRmiContextMap(Map<String, Context> rmiContextMap) {        this.rmiCachedContextMap = rmiContextMap;    }
    public Map<String, NodeRemote> getRemoteObjects() {        return remoteObjects;    }
    public void setRemoteObjects(Map<String, NodeRemote> remoteObjects) {        this.remoteObjects = remoteObjects;    }
    public Map<String, Integer> getStateToSet() {        return stateToSet;    }
    public void setStateToSet(Map<String, Integer> stateToSet) {        this.stateToSet = stateToSet;    }
    public Map<String, Boolean> getNodeUnavailable() {        return nodeUnavailable;    }
    public void setNodeUnavailable(Map<String, Boolean> nodeUnavailable) {        this.nodeUnavailable = nodeUnavailable;    }
    public Map<String, String> getServerIPMap() {        return serverIPMap;    }
    public void setServerIPMap(Map<String, String> aServerIPMap) {        serverIPMap = aServerIPMap;    }
    public List<String> getServernames() {        return serverNames;    }
    public void setServerNames(List<String> serverNames) {        this.serverNames = serverNames;    }
    public int getNumberServers() {        return numberServers;    }
    public void setNumberServers(int numberServers) {        this.numberServers = numberServers;    }
    public Map<String, Integer> getAvailableProcessors() {        return availableProcessors;    }
    public void setAvailableProcessors(Map<String, Integer> availableProcessors) {        this.availableProcessors = availableProcessors;    }
    public static void main(String[] args) {
        Host host = new Host();

JMX MBeans

  • See work to enable EclipseLink MBeans on WebLogic, JBoss, WebSphere and Glassfish in enhancement 316513

JMX MBeans on WebLogic via SUN JConsole

  • Enable the eclipselink properties on the startup script
  • enable Anonymous Admin Lookup Enabled on the domain|security tab in the WebLogic console.

Weblogic11g console jmx anon security.jpg

  • To view MBeans on WebLogic 10.3 use the following standard SUN JDK 1.6 Jconsole application - use these classpath and connection string settings.
  • Set your path to the target JVM - here it should be either the bundled SUN JDK or the JRockit JVM.
  • Launch JConsole
C:\>jconsole -J-Djava.class.path=C:/opt/wls1031_l16/jdk160_11/lib/jconsole.jar;C:/opt/wls1031_l16/jdk160_11/l
ib/tools.jar;C:/opt/wls1031_l16/wlserver_10.3/server/lib/wljmxclient.jar -J-Djmx.remote.protocol.provider.pkgs=weblogic.management.remote -J-Dcom.sun.management.jmxremote
  • Make sure the following propery is set if the platform MBean server is required (the one containing the bea/weblogic packages)

  • You will see the following dialog - select the remote service section.

Weblogic 103 jconsole launch.JPG

  • Note: however this method of launching JConsole restricts you to the MBean tab, to view the other memory, threads, vm summary, classes tabs launch jconsole normally without parameters by selecting the weblogic.Server local process
username/password = weblogic console username/password
  • You will see the following TopLink/EclipseLink tree as well as other application specific management branches in the JConsole view

Jconsole mar 2009 el and com bea trees.JPG

JMX MBeans on WebLogic via JRockit Mission Control (JRMC)

  • Launch JRockit MC (C:\opt\wls10330\jrockit_160_17_R28.0.0-679\bin\jrmc.exe)
  • Connect to the weblogic server process
  • Hit the MBeans Icon and navigate the tree to "TopLink:session"



Oracle WebLogic Server Documentation Links