users@glassfish.java.net

Re: Using local jdbc reference

From: Dies Koper <dies_at_jp.fujitsu.com>
Date: Fri, 17 Aug 2007 09:38:48 +0900

Hello Whartung,

Apologies if I misunderstood your intention, just trying to help.

If you have two applications both looking up "jdbc/myDatasource" but
actually you want them to find different datasources, you need to map
the lookup name to the actual JNDI name.
You can either do this by specifying "mapped-name" in the EJB3.0
deployment descriptor, or by specifying the jndi-name in sun-ejb-jar.xml
[3] of each EAR's ejb-jar module.

Then create the two pools and JDBC Resources with names like
myDatasource1 and myDatasource2.

[1]
[..]
   <resource-ref>
     <res-ref-name>jdbc/myDataSource</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
     <res-sharing-scope>Shareable</res-sharing-scope>
     <mapped-name>jdbc/myDataSource1</mapped-name>
   </resource-ref>
[..]

[2]
<sun-ejb-jar>
   <enterprise-beans>
     <ejb>
       <ejb-name>MyBean</ejb-name>
       <resource-ref>
         <res-ref-name>jdbc/myDataSource</res-ref-name>
         <jndi-name>jdbc/myDataSource1</jndi-name>
       </resource-ref>
     </ejb>
   </enterprise-beans>
</sun-ejb-jar>

PS: I'm not sure whether "jndi/" should be included or not in the
examples above. Please let me know when you tried it out :)

Regards,
Dies

glassfish_at_javadesktop.org wrote:
> Is there a way to use a local jdbc reference to a DataSource and then map it to a different on in the app server?
>
> For example if I have an application with jdbc/myDataSource in it:
>
> [code]
> @SessionBean
> public class MyBean implements MyBeanLocal {
> @Resource(name = "jdbc/myDataSource")
> private DataSource ds;
>
> ...
> }
> [/code]
>
> Right now, I simply go to the admin console, create a connection pool and then the jdbc resource.
>
> But if I want to run another app using the same bean (in a different EAR) but talking to a different connection pool, how and where do I make that change so that the two can co-exist?
> [Message sent by forum member 'whartung' (whartung)]
>
> http://forums.java.net/jive/thread.jspa?messageID=231230