I'm going a little crazy trying to make the Java EE 6 webapp portable between Glassfish AS 3.x and JBoss AS 6 (and 7 on release).
Since each server maps JNDI names for data sources in different ways, I need to specify the internal name of the private application for the data source in the persistence.xml file, and then use glassfish-web.xml or jboss-web.xml (depending on the situation) to map this to the real name of the data source on the server.
The theory is simple (well, for EE):
- Use the internal name in the persistence.xml file, for example, "my-datasource"
- Add the resource-ref entry to web.xml, declaring that your application needs a resource called "my-datasource"
- Add the mapping in glassfish-web.xml and jboss-web.xml with the appropriate server syntax, declaring that "my-datasource" should be mapped to the data source provided by the application server, named "real-DS-created-by -admin "
Unfortunately, the theory is about how this is possible, because for life I can not get it to work in Glassfish AS 3.1, 3.1.1, 3.2 beta, JBoss AS 6 or JBoss AS 7 beta. Right now I'm focusing on getting him to work on Glassfish.
Glassfish reports "Invalid resource: my-datasource__pm" when I try to deploy an application that references "my-datasource" in the persistence.xml file:
<?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="org.example_glassfish-webxml-datasource-jndi-mapping_war_1.0-SNAPSHOTPU" transaction-type="JTA"> <jta-data-source>my-datasource</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties/> </persistence-unit> </persistence>
and maps it to a known existing data source via web.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <resource-ref> <res-ref-name>my-datasource</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> </web-app>
... and glassfish-web.xml:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd"> <glassfish-web-app error-url=""> <resource-ref> <res-ref-name>my-datasource</res-ref-name> <jndi-name>realdsname</jndi-name> </resource-ref> </glassfish-web-app>
"asadmin list-jndi-entries" shows the actual JNDI name of the data source exactly as it appears in glassfish-web.xml, as well as listing another entry with the suffix "__pm" created by Glassfish:
$ asadmin list-jndi-entries .... unrelated output .... realdsname__pm: javax.naming.Reference realdsname: javax.naming.Reference
Needless to say, the wall completely covers me. Any ideas on what I am missing?