EclipseLink/Examples/JPA/WLS AppScoped DataSource

From Eclipsepedia

< EclipseLink‎ | Examples‎ | JPA
Revision as of 11:12, 9 September 2008 by Douglas.clarke.oracle.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

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

DataSource Definition

Invalid language.

You need to specify a language like this: <source lang="html4strict">...</source>

Supported languages for syntax highlighting:

4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, arm, asm, asp, asymptote, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcl, dcpu16, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, freeswitch, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, haxe, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, ldif, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, nagios, netrexx, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, octave, oobas, oorexx, oracle11, oracle8, otj, oxygene, oz, parasail, parigp, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, pys60, python, q, qbasic, rails, rebol, reg, rexx, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, spark, sparql, sql, stonescript, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, upc, urbi, uscript, vala, vb, vbnet, vedit, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic


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