users@glassfish.java.net

How to find a Datasource by using Resource-Reference ?

From: <glassfish_at_javadesktop.org>
Date: Tue, 25 Aug 2009 02:50:15 PDT

Hi there,

I hope this is not too bad noob question :)

I have question about how to configure glassfish to find a Datasource using ejb-jar and sun-ejb-jar. The descriptors can be seen in the Admin Console.

Here's the ejb-jar:

<ejb-jar>
  <enterprise-beans>
    <session>
      <ejb-name>****</ejb-name>
      <home>com.....****Home</home>
      <remote>com.....***Remote</remote>
      <ejb-class>com......****</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
     <resource-ref>
        <res-ref-name>jdbc/myDataSource</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
      </resource-ref>
    </session>
  </enterprise-beans>
</ejb-jar>

and here the sun-ejb-jar:
<sun-ejb-jar>
    <enterprise-beans>
        <ejb>
    <ejb-name>***</ejb-name>
    <jndi-name>***</jndi-name>
      <resource-ref>
        <res-ref-name>jdbc/myDataSource</res-ref-name>
        <jndi-name>myPool</jndi-name>
      </resource-ref>
    <pass-by-reference>false</pass-by-reference>
 </ejb>
 </enterprise-beans>
</sun-ejb-jar>


As you can see, I have a resource-ref to something called myDataSource, which I want to use myPool.
"myPool" is existent (it's a JDBC resource), I can ping the corresponding ConnectionPool and make a lookUp.

But if I want to make a lookup on "myDatasource" I always get nothing. Here's what I tried:

dataSource = (DataSource) ctx.lookup("myPool"); --> this works!
dataSource = (DataSource) ctx.lookup("myDataSource");
dataSource = (DataSource) ctx.lookup("jdbc/myDataSource");
dataSource = (DataSource) ctx.lookup("java:comp/env/jdbc/myDataSource");

What am I doing wrong? Is it a programming issue or a configuration issue?

Thank very much

Veronika
[Message sent by forum member 'tesis_glassfish' (vbrem_at_tesis.de)]

http://forums.java.net/jive/thread.jspa?messageID=361834