• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reuse of Data Source

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am working on an application which contains multiple EJB modules,one web application and multiple standalone java projects(Project Utility jars which assist those modules).


I am using Web Sphere 6.0 along with RAD as an IDE.

For this project we configured one data source with a jndi name in our Web Sphere admin console. We have created a j2c authentication alias(Container-managed authentication alias by giving user name and password). Our application is using this datasource.

Here I am facing two problems.

1. I tried handling the db code(getting data source from JNDI lookup and connection) in a standalone application in my project.

Here is the code that I wrote to get the data source.



But when I try to get the connection by using ds.getConnection()....it is giving exception as ....userid is null...But I have provided userid and password to that(Even TestConnection also successful)

I tried using ds.getConnection(username,password) by hardcoding username and password...it worked for me....But Why it is not using the container managed authentication that I specified in the IBM console?

2. One more thing is I added a resource-ref to a ejb module(By referring to the JNDI db2/jndi/project in ibm-ejb-jar-bnd.xmi)ejb-jar.xml like below.



I am able to access this datasource and get connection in this EJB project(Using java:comp/env/jdbc/DataSource).

But I am not able to use this(the datasource configured above) in other EJB modules. Can I reuse the same resource-ref(The one mentioned above) in other EJB modules without configuring same jdbc/DataSource again and again?

Is it possible the datasource configured in one EJB project to be used in other EJB projects?

I tried adding the same resource-ref in Web Application web.xml, Can I use this reference in ejb modules without configuring again?

Any help is really appreciated.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Venki,

You have only one datasource for your entire application, which you configure just once; additionally, you declare N resource-ref "pointing" to that datasource, one for each module (web or ejb) that is going to use it.

So, of course you reuse your datasource, you just have to declare the proper references everywhere you need it.

...or don't use resource-ref. Not using it is "deprecated" since WAS 6.0, but it still works and you won't have to bother creating references here and there. Just be sure to properly set the container-managed authentication settings in the datasource configuration page of the admin console.
 
venki venki
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jaime Garc�a for your reply.

As you suggested, I tried using the direct JNDI look up of the data source which is a deprecated one as shown below.

DataSource ds = (DataSource)ic.lookup("db2/jndi/project");
Connection con= ds.getConnection();

But it has given me a exception "userid is null: in the RAD console.(With the configuration of container managed authentication alias also)

I tried two options to get rid of this.

1. I tried by giving username and password as
ds.getConnection(username,password). It is working then. So it is sure that direct JNDI look up is not using Container managed authentication.

2. I also tried by configuring a component managed authetication alias(Selecting the drop down option(Use component managed authentication alias) as J2C authentication alias in IBM console which I created earlier for container managed authentication). Then the above code is working and in the RAD console I got below trace.

res-auth: 1 (APPLICATION) //Component managed auth
res-isolation-level: 0 (TRANSACTION_NONE)
res-sharing-scope: true (SHAREABLE)
loginConfigurationName: null
loginConfigProperties: null

I googled to find out the differences between container managed authentication and component managed authentication. But I can't able to find anywhere. Can you give the advantages and disadvanges of using one over the other. Which approach is the best to use?

Thanks
Venki
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic