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.
EclipseLink/Examples/JPA/WLS AppScoped DataSource
< EclipseLink | Examples | JPA
Revision as of 11:12, 9 September 2008 by Unnamed Poltroon (Talk) (New page: == How to use Application Scoped Data Sources in WebLogic with EclipseLink JPA == === DataSource Definition === <source lang="xml> <?xml version = '1.0' encoding = 'windows-1252'?> <jdbc...)
Contents
How to use Application Scoped Data Sources in WebLogic with EclipseLink JPA
DataSource Definition
<?xml version = '1.0' encoding = 'windows-1252'?> <jdbc-data-source xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-jdbc.xsd" xmlns="http://www.bea.com/ns/weblogic/jdbc-data-source"> <name>SimpleDS</name> <jdbc-driver-params> <url>jdbc:oracle:thin:@localhost:1521:ORCL</url> <driver-name>oracle.jdbc.OracleDriver</driver-name> <properties> <property> <name>user</name> <value>scott</value> </property> <property> <name>servername</name> <value>localhost</value> </property> <property> <name>portnumber</name> <value>1521</value> </property> <property> <name>sid</name> <value>ORCL</value> </property> </properties> <password-encrypted>tiger</password-encrypted> </jdbc-driver-params> <jdbc-connection-pool-params> <initial-capacity>2</initial-capacity> <max-capacity>10</max-capacity> <test-connections-on-reserve>true</test-connections-on-reserve> <test-table-name>SQL SELECT 1 FROM DUAL</test-table-name> </jdbc-connection-pool-params> <jdbc-data-source-params> <jndi-name>SimpleDS</jndi-name> <scope>Application</scope> <global-transactions-protocol>TwoPhaseCommit</global-transactions-protocol> </jdbc-data-source-params> </jdbc-data-source>
WebLogic Application Configuration
In the EAR you will have /META-INF/weblogic-application.xml where the JDBC module is defined.
<wls:module> <wls:name>SimpleDS</wls:name> <wls:type>JDBC</wls:type> <wls:path>META-INF/simple-jdbc.xml</wls:path> </wls:module>
JPA: persistence.xml
In the persistence.xml's definition of the persistence-unit you will need to specify an additional property so EclipseLink can lazily look up the application scoped data source.
<?xml version="1.0" encoding="windows-1252" ?> <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" version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"> <persistence-unit name="employee" transaction-type="JTA"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <jta-data-source>SimpleDS</jta-data-source> <properties> <property name="eclipselink.target-server" value="WebLogic_10" /> <property name="javax.persistence.jtaDataSource" value="java:/app/jdbc/SimpleDS" /> </properties> </persistence-unit> </persistence>
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.