users@glassfish.java.net

Re: You could follow either of

From: <forums_at_java.net>
Date: Sun, 3 Apr 2011 23:04:53 -0500 (CDT)

Hi,

Here is my story:

I have a persistence jar that contains the following persistence.xml file:

{code}

<persistence-unit name="myPU" transaction-type="JTA">
        <jta-data-source>jdbc/myDS</jta-data-source>
[...]
 </persistence-unit>
{/code}

I want to use this jar in a war file (deployed in Embedded GF 3.1) . So, all
I need is  to create a DS and bind it to jdbc/myDS. Sounds fairly
straightforward, and I thought that having the following
glassfish-resources.xml in WEB-INF would do the trick:

{code}

 <jdbc-resource pool-name="myPool"  jndi-name="jdbc/myDS"
object-type="user" enabled="true" />
    <jdbc-connection-pool name="myPool"
                         
datasource-classname="oracle.jdbc.pool.OracleDataSource"
                         
res-type="javax.sql.DataSource" >
        [...]
    </jdbc-connection-pool>

{/code}

But it does not  work. It's like if GF ignored this resource defintion. I'm
getting the following error with GF scans my persistence jar:

{code}

SEVERE: Invalid resource : jdbc/myDS__pm
java.lang.RuntimeException: Invalid resource : jdbc/ubcRegiDomainDS__pm
    at
com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:539)
    at
com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource(ConnectorRuntime.java:468)

{/code}

I thought "Okay, GF really wants that resource to be bound to jdbc/myDS__pm,
let's cooperate", and I changed the jndi name to:

{code}

<jdbc-resource pool-name="myPool"  jndi-name="jdbc/myDS__pm"
object-type="user" enabled="true" />

{/code}

Same result. I even tried the allow-non-component-callers="true" option on
the <jdbc-connection-pool> element.

Then I tried to set the jndi name via web.xml & glassfish-web.xml:

web.ml:

{code}

   <resource-ref>
        <res-ref-name>jdbc/myDS</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>

{/code}

glassfish-web.xml:

{code}

    <resource-ref>
         <res-ref-name>jdbc/myDS</res-ref-name>
         <jndi-name>jdbc/myDS</jndi-name>
     </resource-ref>

{/code}

No luck.

When I use java:app/jdbc/myDS as the jndi name, everything works fine
(without web.xml nor glassfish-web.xml). That's why I thought I needed to
prefix the jndi name with 'java:'.

So, what's the magic trick to bind a datasource to 'jdbc/myDS'? Your response
suggests it's possible, but  I tried dozens of variations in
web.xml/glassfish-web.xml/glassfish-resources.xml to no avail.

Thanks,

Vincent


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