users@glassfish.java.net

Indirection of persistence.xml datasource via web.xml and glassfish-web.xml:

From: <forums_at_java.net>
Date: Wed, 13 Jul 2011 02:47:37 -0500 (CDT)

 Hi all

I've been struggling for days to make my app portable between Glassfish 3.1.1
and JBoss AS 7. The main issue I'm encountering is with JNDI naming of
datasources.

The "standard" approach to app-server differences in JNDI naming is to map an
application-local name to a container-provided name by adding a resource-ref
in web.xml, then mapping it to a container jndi name using glassfish-web.xml
/ jboss-web.xml . I've been completely unable to get this to work with either
Glassfish or JBoss, both of which seem to completely ignore the indirection
and try to look the app-local name up directly in the container JNDI
namespace.

I've just been informed [1]that this is exactly how it's supposed to work:

/"The resource-ref element that you refer to above defines an indirection
within a component name space. A PersistenceUnit (EMF) is not initialized
within a component and hence always uses the global name space to look up
data sources."
/

This leads me to the question: *how on earth are you supposed to avoid
hard-coding an app-server-specific data source name in persistence.xml* ?
Isn't that what resource-ref and server-specific deployment descriptor
indirection is /for/? Isn't it bizarre to deny the "new standard" method of
data access, JPA 2.0, use of the same mapping system and rules already
available to apps that use JDBC directly?

How do I work around this? Make app-server-specific overlays for my WAR files
that add a different persistence.xml for each server? That just can't be
right.

 


[1]
http://java.net/jira/browse/GLASSFISH-17024?focusedCommentId=316730&amp;page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_316730

--
[Message sent by forum member 'ringerc']
View Post: http://forums.java.net/node/821542