Skip to main content

Application scoped resources and persistence.xml do not work together, what I did wrong?

5 replies [Last post]
gray
Offline
Joined: 2006-04-07
Points: 0

I've got pretty simple application packaged as ear. This application include one ejb module, one datamodel.jar (inside lib directory which include persistence.xml) and glassfish-resources.xml in META-INF subdirectory of ear.
Contents of persistence.xml:

...
    < persistence-unit name="inventory-datamodel" transaction-type="JTA">
        < provider>org.eclipse.persistence.jpa.PersistenceProvider</ provider>
        < jta-data-source>java:app/jdbc/InventoryPool2</ jta-data-source>
...

Contents of glassfish-resources.xml:

< resources>
    < jdbc-connection-pool datasource-classname="org.postgresql.xa.PGXADataSource"
                          res-type="javax.sql.XADataSource"
                          name="java:app/AppInventoryPool"
                          validate-atmost-once-period-in-seconds="10" >
        < property name="databaseName" value="hp-inventory"/>
        < property name="serverName" value="hp-inventory-stage"/>
        ....
    </ jdbc-connection-pool>
    < jdbc-resource pool-name="java:app/AppInventoryPool" jndi-name="java:app/jdbc/InventoryPool2" />
</ resources>

Deployment of application goes fine. But when I restart server I got following exception stack:

java.lang.RuntimeException: javax.naming.NameNotFoundException: No object bound to name java:app/jdbc/InventoryPool2
at org.glassfish.persistence.jpa.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:111)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:155)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:120)
at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:224)
at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:495)
at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:233)
at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:871)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:410)
at com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:375)
...

This error leads to uninitialized EJBs and other stuff (e.g. iiop listener do not start properly). I assume that this happens because ApplicationLoaderService invoked before ApplicationScopedResourcesManager - i.e. resources from glassfish-resources.xml (or may be domain.xml) not yet have been read and lookup do not return anything. I want to mention that this problem only related to application scoped resources, NOT to globally defined.

My question is anyone know how to workaround this? (Except for creating global resources)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
craigday
Offline
Joined: 2004-06-28
Points: 0

We just came across the same issue. The initial deploy works fine but on restart the resources are not available as the application is (re)starting up. The resources do ultimately appear to be registered correctly because we can see them in the web admin console. The problem seems to be related to clustering as it only occurs when we deploy to a local standalone instance, not when we deploy (and restart) on the DAS.

vetler
Offline
Joined: 2010-05-25
Points: 0

For the record: this works fine for me on Glassfish 3.1.2.2, with a WAR-file containing EJBs, and glassfish-resources.xml in the WEB-INF directory.

craigday
Offline
Joined: 2004-06-28
Points: 0

I have produced a testcase and raised a ticket.

http://java.net/jira/browse/GLASSFISH-19161

Cheers
Craig

jr158900
Offline
Joined: 2005-04-13
Points: 0

Which version of GlassFish do you use.
"asadmin version --verbose" will provide the information. Please raise an issue in JIRA (and if possible a test-case too).

craigday
Offline
Joined: 2004-06-28
Points: 0

I have produced a testcase and raised a ticket.

http://java.net/jira/browse/GLASSFISH-19161

Cheers
Craig