Revision as of 11:56, 18 November 2008

Contents

How to use Application Scoped Data Sources in WebLogic with EclipseLink JPA

This how-to describes the use of application scoped data-sources within a WebLogic Application Server (version 10.3). These steps are necessary as the WebLogic container does not initialize application scoped data sources before the JPA bootstrapping is performed. Without these steps EclipseLink will be provided a null data-source and will throw an exception during its initialization.

The configuration involves a few simple configuration steps:

Define the new data-source in a *-jdbc.xml configuration file. (EAR)

Add the JDBC module to the WebLogic Application Configuration (EAR)

Configure the JPA persistence unit to use the application scoped data source (EJB)

1. DataSource Definition

An application scoped data source can be specified by providing a <name>-jdbc.xml file within the META-INF folder of your application's EAR. The following illustrates how the file might be defined. The important part of this configuration is the <scope>Application</scope> within the jdbc-data-source-params section.

The framework for the this <name>-jdbc.xml file can be generated by creating a globally scoped datasource on the WebLogic administration page, not associating it with a server and adding the <scope> element manually.

JPA: persistence.xml

In the persistence.xml's definition of the persistence-unit you will need to specify an additional fully qualified "javax.persistence.jtaDataSource" property so EclipseLink can lazily look up the application scoped data source.
This additional property "java:/app/jdbc/SimpleAppScopedDS" is the workaround for the following issue 246126. Please retain the original <jta-data-source> element for future compatability when this workaround is no longer required.

In this example a JTA data source is being used so the property required is javax.persistence.jtaDataSource. If however you are using a non-jta-data-source then you should use the javax.persistence.nonJtaDataSource property to specify the JNDI name to use.