glassfish-resources.xml is ignored during the deployment of a Java EE application.
Environment:
NetBeans 8.0.1
GlassFish 4.1
Java DB 10.10.2.0 - (1582446)
Here is a procedure to reproduce the problem.
1. With Java DB (intalled in C:\Program Files\glassfish-4.1\javadb), I create a new database db1.
2. I create a Web Application with GF 4.1, without any framework.
3. In the project, New > Entity Class. I check "Create Persistence Unit".
New Data Source jdbc/db1 with database connection to the database created in the first step.
Table generation strategy: create.
glassfish-resources.xml generated:
persistence.xml generated:
jdbc/db1
false
4. New session bean stateless.
Sb1
Insert Code and Use entity manager.
Code of the EJB:
package ejb;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless
public class Sb1 {
@PersistenceContext(unitName = "TestPbDSPU")
private EntityManager em;
public void persist(Object object) {
em.persist(object);
}
}
5. Deploy.
Glassfish 4.1 starts.
Problem:
Grave: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method
Grave: java.lang.RuntimeException: Invalid resource : jdbc/db1__pm
at com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:593)
at com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource(ConnectorRuntime.java:517)
at org.glassfish.persistence.common.PersistenceHelper.lookupPMResource(PersistenceHelper.java:63)
at org.glassfish.persistence.jpa.ProviderContainerContractInfoBase.lookupDataSource(ProviderContainerContractInfoBase.java:71)
at org.glassfish.persistence.jpa.PersistenceUnitInfoImpl.(PersistenceUnitInfoImpl.java:108)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:142)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.(PersistenceUnitLoader.java:107)
at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:223)
at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:510)
at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:230)
at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:925)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:434)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:539)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:535)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
...
6. If I add the connection pool and the JDBC resource by asadmin, no problem with glassfish-resources.xml and no more problem with the deployment of the application because the JDBC resource is registered in the server.
add-resources C:/Users/richard/Documents/NetBeansProjects/TestPbDS/setup/glassfish-resources.xml