Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to specify Resource References for data sources?

22 views
Skip to first unread message

Pavanapuresan

unread,
Sep 19, 2001, 12:57:47 PM9/19/01
to
HI all,
I use WAS AEs on Win 2K with DB2 7.2.
I have a problem with looking up Data Sources from a connection pool. All
the session beans in my application refer to an external resource reference,
whose (ejb-jar)xml excerpt is as follows:

<resource-ref>
<res-ref-name>jdbc/eBanking</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

In the resource reference area of the session bean in the AAT GUI, the
binding name is not specified. In the general tab, however the above details
are displayed correctly.

I am encountering a few problems which i'll list below. I hope somebody can
help me with them:

1. When i try to access any session bean, which calls the following bit of
code in the create method :

initial = new InitialContext();
// create a data source
dataSource = (DataSource) initial.lookup("java:comp/env/jdbc/eBanking");
plConn = dataSource.getConnection();

it fails with the following exception :

javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context
"java:".
at
com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1443)
at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:824)
at com.ibm.ws.naming.urlbase.UrlContext.lookup(UrlContext.java:1166)
at com.ibm.ws.naming.urlbase.UrlContext.lookup(UrlContext.java:1158)
at com.ibm.ws.naming.urlbase.UrlContext.lookup(UrlContext.java:1210)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at
com.mki.ebanking.manager.beans.AbstractBanksiteManager.initialiseAbstractBan
ksiteManager.java:44)
at
com.mki.ebanking.beans.lclcustyp.LclcustypManagerBean.ejbCreateLclcustypMana
gerBean.java:106).....

I am not able to get the datasource consequently. According to my
understanding the resource reference for the data source is being accessed
properly in the code. Im not sure why its not able to look it up.

2. I therefore specified a name in the bindings section of the resource
reference. I gave it the JNDI name - jdbc/eBanking - same as the name of the
resource. When i tried accessing it now it failed with the following
exception :

javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context
"java:".
at
com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1443)
at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:824)
at com.ibm.ws.naming.urlbase.UrlContext.lookup(UrlContext.java:1166)
at com.ibm.ws.naming.urlbase.UrlContext.lookup(UrlContext.java:1158)
at com.ibm.ws.naming.urlbase.UrlContext.lookup(UrlContext.java:1210)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at
com.mki.ebanking.manager.beans.AbstractBanksiteManager.initialiseAbstractBan
ksiteManager.java:44)
at
com.mki.ebanking.beans.lclcustyp.LclcustypManagerBean.ejbCreateLclcustypMana
gerBean.java:106).....

I tried then with various other combinations, once with
java:comp/env/jdbc/eBanking itself, but without any success. Only the
exceptions kept differing, the end result was the same.

3. I then removed all jndi names for the resources, installed and restarted
the application. For the beans, whose resource JNDI names i had just
removed, the std. output log displayed this error:

[01.09.19 17:04:09:218 BST] 2877601f IndirectJndiL W NMSV0701W: An
IndirectJNDILookup object was created with an empty name. Lookups using this
object will fail.
java.lang.Throwable
at
com.ibm.ws.naming.util.IndirectJndiLookup.init(IndirectJndiLookup.java:116)
at
com.ibm.ws.naming.util.IndirectJndiLookup.<init>(IndirectJndiLookup.java:61)
at
com.ibm.ws.naming.util.IndirectJndiLookupFactoryImpl.createIndirectJndiLooku
p(IndirectJndiLookupFactoryImpl.java:34)
at
com.ibm.ejs.container.BeanMetaData.populateJavaNameSpace(BeanMetaData.java:1
365)
at
com.ibm.ejs.container.BeanMetaData.completeInitialization(BeanMetaData.java:
753)
at
com.ibm.ejs.container.EJSContainer.loadBeanMetaData(EJSContainer.java:1518)
at
com.ibm.ejs.container.EJSContainer.getHomeInstance(EJSContainer.java:1255)
at com.ibm.ejs.container.EJSContainer.startBean(EJSContainer.java:1219)
at com.ibm.ws.runtime.BeanHelper.startBean(BeanHelper.java:154)
at com.ibm.ws.runtime.EJBEngine.addEjbModule(EJBEngine.java:437)
at com.ibm.ws.runtime.Server.startModule(Server.java:605)
at
com.ibm.ws.runtime.StandardServer.initializeModules(StandardServer.java:321)
at
com.ibm.ws.runtime.StandardServer.initializeRuntime0(StandardServer.java:349
)
at com.ibm.ws.runtime.Server.initializeRuntime(Server.java:882)
at com.ibm.ws.runtime.StandardServer.main(StandardServer.java:519)
at java.lang.reflect.Method.invoke(Native Method)
at com.ibm.ws.bootstrap.WSLauncher.main(WSLauncher.java:158)

However, the bean deploys. It seems to be only for the resource reference.
When the session bean is accessed in this case the following exception is
thrown:

com.ibm.websphere.naming.CannotInstantiateObjectException: Exception
occurred while attempting to get an instance of the object for the specified
reference object. Root exception is javax.naming.NamingException: Failed to
lookup the object configured with a null or empty name
at
com.ibm.ws.naming.util.IndirectJndiLookupObjectFactory.getObjectInstance(Ind
irectJndiLookupObjectFactory.java:123)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:308)
at
com.ibm.ws.naming.urlbase.UrlContextHelper.isReference(UrlContextHelper.java
:115)
at
com.ibm.ws.naming.urlbase.UrlContextHelper.processBoundObjectForLookup(UrlCo
ntextHelper.java:229)
at com.ibm.ws.naming.urlbase.UrlContext.lookup(UrlContext.java:1181)
at com.ibm.ws.naming.urlbase.UrlContext.lookup(UrlContext.java:1158)
at com.ibm.ws.naming.urlbase.UrlContext.lookup(UrlContext.java:1210)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at
com.mki.ebanking.beans.generalfunctions.picklistmanager.PickListManagerBean.
ejbCreate(PickListManagerBean.java:59)

I have to admit, im stumped. All that i can make out of these errors is that
the system is not able to create a DataSource. And that its somehow related
to an incorrect JNDI name for the resource. But I have no ideas about the
what, where, how, and why.
I will be very gald of ANY help on this score. Im way behind my deliverable
date.


Thanks and regards,

Pavan


Pavanapuresan

unread,
Sep 19, 2001, 2:16:00 PM9/19/01
to
Just FYI,
In Case 2. the std_error_log has the following error :

com.ibm.websphere.ce.cm.StaleConnectionException: Connection is closed
at
com.ibm.ejs.cm.proxy.ConnectionProxy.getConnection(ConnectionProxy.java:656)
at
com.ibm.ejs.cm.proxy.ConnectionProxy.translateException(ConnectionProxy.java
:142)
at
com.ibm.ejs.cm.proxy.ConnectionProxy.createStatement(ConnectionProxy.java:42
1)
at
com.mki.ebanking.beans.generalfunctions.picklistmanager.PickListManagerBean.
getResults(PickListManagerBean.java:266)
at
com.mki.ebanking.beans.generalfunctions.picklistmanager.PickListManagerBean.
lookUp(PickListManagerBean.java:161)
at
com.mki.ebanking.beans.generalfunctions.picklistmanager.EJSRemoteStatefulPic
kListManager.lookUp(EJSRemoteStatefulPickListManager.java:49)

TAR

Pavan

Pavanapuresan <pav...@midas-kapiti.com> wrote in message
news:9oaiq3$pmo$1...@news.boulder.ibm.com...

Alex Matthews

unread,
Sep 19, 2001, 3:14:24 PM9/19/01
to
Have you either

1. Specified the JNDI name in the bindings tab in AAT (this is NOT the
same as the stuff that appears in ejb-jar.xml)

or

2. Specified the correct binding when you install the app?

The entry in ejb-jar.xml, that is displayed in the general tab in AAT is
declaring that java:comp/env/jdbc/eBanking is a name that your EJB uses.
The binding is application-server (vendor and instance) specific
information that says what the 'real' JNDI name of the resource is -
i.e. what the container should look up and actually give to the EJB when
the reference is requested.

There's a section in the 6134 redbook on this if I haven't explained
this well enough.

Alex.

Pavanapuresan

unread,
Sep 20, 2001, 4:41:12 AM9/20/01
to
Thanks Alex, i think i understand the problem now.
I specified the JNDI name in the bindings tab in AAT. If this name is not
the same as the stuff that appears in the ejb-jar.xml, then what should it
be ?

> The binding is application-server (vendor and instance) specific
> information that says what the 'real' JNDI name of the resource is -
> i.e. what the container should look up and actually give to the EJB when
> the reference is requested.

1. Do u know the real JNDI name of the resource?
2. Another doubt, should this information be present in the
ibm-ejb-jar-bnd.xmi document?
3. Which section in the redbook discusses this?

TAR

Pavan


Alex Matthews <al...@xelacom.com> wrote in message
news:3BA8EE90...@xelacom.com...

Alex Matthews

unread,
Sep 20, 2001, 5:47:18 AM9/20/01
to
1. The real name is whatever name you gave the data source when you
created it
2. Yes, or it can be specified (or overridden) when you install the
module into WAS
3. Well, for a start Chapter 13, section 'Using JNDI' describes the
programming concepts, and Chapter 9, section 'Working with meta-data'
discusses the differences between J2EE and WebSphere-specific files

Alex.

Pavanapuresan

unread,
Sep 20, 2001, 6:06:41 AM9/20/01
to
Alex, like i said in an earlier post, when i specify the binding name as
jdbc/eBanking, which is the name of the data source, and i access the
session bean, it throws the following exception in the standard error log:

com.ibm.websphere.ce.cm.StaleConnectionException: Connection is closed
at
com.ibm.ejs.cm.proxy.ConnectionProxy.getConnection(ConnectionProxy.java:656)
at
com.ibm.ejs.cm.proxy.ConnectionProxy.translateException(ConnectionProxy.java
:142)
at
com.ibm.ejs.cm.proxy.ConnectionProxy.createStatement(ConnectionProxy.java:42
1)
at
com.mki.ebanking.beans.generalfunctions.picklistmanager.PickListManagerBean.
getResults(PickListManagerBean.java:266)
at
com.mki.ebanking.beans.generalfunctions.picklistmanager.PickListManagerBean.
lookUp(PickListManagerBean.java:161)
at
com.mki.ebanking.beans.generalfunctions.picklistmanager.EJSRemoteStatefulPic

kListManager.lookUp(EJSRemoteStatefulPickListManager.java:49)....

BTW, i have specified the resource jndi name for only the session bean that
i am testing. For the others, its still empty. That wouldn't be a problem,
would it?

In weblogic, the weblogic specific xml file has the following snippet of
info. regarding the data source for the session bean:
<reference-descriptor>
<resource-description>
<res-ref-name>jdbc/eBanking</res-ref-name>
<jndi-name>weblogic.jdbc.jts.eBanking</jndi-name>
</resource-description>
</reference-descriptor>

Could u paste a snippet of the websphere specific xmi document that contains
this information of the resource reference?

TAR

Pavan

Alex Matthews <al...@xelacom.com> wrote in message

news:3BA9BB26...@xelacom.com...

Alex Matthews

unread,
Sep 20, 2001, 8:47:14 AM9/20/01
to
The StaleConnectionException usually means that the database was shut
down or otherwise went away - a connection obtained from the connection
pool is invalid because the database instance it was connected to has
gone away. WAS will discard the connection from the pool - you should
consider retrying the operation - once all the bad connections have been
removed from the pool WAS will obtain new connections (assuming the
database is back up).

If the database has not been restarted, and you haven't had any other
sort of interruption (network outage, etc) that would cause a pooled
connection to become invalid, we'll have to look a bit closer. What
database are you using, and how have you configured the datasource, BTW?

Alex.

Pavanapuresan

unread,
Sep 20, 2001, 9:41:26 AM9/20/01
to
I chose a wrong bean to try the test out, i guess. I tried it with another
bean and that bean was able to retrieve and use the DataSource without a
problem. I have just made some code changes to the StaleConnectionException
generating bean and redeploying it.
Im using DB2 7.2 which resides on the same machine as the WAS server.
I created a datasource using the admin console, under the JDBC Driver. In
the AAT, i also defined a default data source with default authorization
under the bindings tab of the EJB module.
Could u also paste a snippet of the data source jndi name in the bindings
document of any of your beans ? I'd much appreciate that. Right now i have
to specify it for all of my 60 session beans manually and its quite tiresome
as u might imaigine.

Pavan

Alex Matthews <al...@xelacom.com> wrote in message

news:3BA9E552...@xelacom.com...

Alex Matthews

unread,
Sep 20, 2001, 10:52:32 AM9/20/01
to
All my code uses CMP so my bindings for datasources is no use to you...

Why not do it once and check your own bindings XML?

Alex.

Pavanapuresan

unread,
Sep 20, 2001, 11:07:54 AM9/20/01
to

Ok, thanks anyway. I found the files. I've got the hang of it now. Thanks,
Alex

Alex Matthews <al...@xelacom.com> wrote in message

news:3BAA02B0...@xelacom.com...

0 new messages