Skip to main content
Jump to: navigation, search

EclipseLink/Examples/JPA/WLS AppScoped DataSource

< EclipseLink‎ | Examples‎ | JPA
Revision as of 11:46, 9 September 2008 by (Talk | contribs) (JPA: persistence.xml)

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:

  1. Define the new data-source in a *-jdbc.xml configuration file. (EAR)
  2. Add the JDBC module to the WebLogic Application Configuration (EAR)
  3. Configure the JPA persistence unit to use the application scoped data source

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.

<?xml version = '1.0' encoding = 'windows-1252'?>
<jdbc-data-source xmlns:xsi=""
      <test-table-name>SQL SELECT 1 FROM DUAL</test-table-name>

WebLogic Application Configuration

In the EAR you will have /META-INF/weblogic-application.xml where the JDBC module needs to be defined. This simply registers the data source defined in step 1 for use in your application.


JPA: persistence.xml

In the persistence.xml's definition of the persistence-unit you will need to specify an additional "javax.persistence.jtaDataSource" property so EclipseLink can lazily look up the application scoped data source. This additional property 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.

<?xml version="1.0" encoding="windows-1252" ?>
<persistence xmlns:xsi=""
  version="1.0" xmlns="">
  <persistence-unit name="employee" transaction-type="JTA">
      <property name="" value="WebLogic_10" />
      <property name="javax.persistence.jtaDataSource" value="java:/app/jdbc/SimpleDS" />

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.

Back to the top