java:comp/DefaultDataSource

@Resource(name="myDataSource", lookup="java:comp/DefaultDataSource")

DataSource myDS;

@Resource(name="myDataSource")

DataSource myDS;

Section E.5.5.20 in the href="http://download.oracle.com/otndocs/jcp/java_ee-7-pr-spec/index.html">JavaEE 7 Platform specification defines a new Default Data Sourcethat must be provided by a Java EE 7-compliant runtime. Thispre-configured data source can be used by application for accessingthe associated database. It is accessible to the application underthe JNDI name:This can be accessed in the application as:If the binding is not specified, the mapping of the reference willdefault to this default data source. So the above fragment isequivalent to:Section 8.2.1.5 in the href="http://download.oracle.com/otndocs/jcp/persistence-2_1-pr-spec/index.html">JPA2.1 specification says

If neither jta-data-source and non-jta-data-source

elements are specified, the deployer must specify a JTA data

source at deployment or a JTA data source must be provided by

the container, and a JTA

EntityManagerFactory will be created

to correspond to it.



Per.book

<?xml version="1.0" encoding="UTF-8"?>

<persistence version="2.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_2_0.xsd">

<persistence-unit name="myPU" transaction-type="JTA">

<jta-data-source>java:comp/DefaultDataSource</jta-data-source>

</persistence-unit>

</persistence>





<?xml version="1.0" encoding="UTF-8"?>

<persistence version="2.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_2_0.xsd">

<persistence-unit name="movieplex7PU" transaction-type="JTA"/>

</persistence>





jta-data-source

jdbc/__default

./bin/asadmin list-jdbc-resources

jdbc/sample

jdbc/__TimerPool

jdbc/__default

Command list-jdbc-resources executed successfully.





This means a Java EE 7 application can have the followingpersistence.xml:This is semantically equivalent to:Notice, noIn both cases, the default data source will be provisioned andavailable to the application. In GlassFish 4, this is bound to theJDBC resourceAnd this can be verified by giving the command:Lesser XML and more defaults makes Java EE 7 more lightweight anduser friendly!Download href="http://dlc.sun.com.edgesuite.net/glassfish/4.0/promoted/">GlassFish4.0 promoted build and try it today!