geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Siraj Mohamed" <Si...@virtusa.com>
Subject Looking up the datasource in a session bean constructor
Date Wed, 05 Apr 2006 11:07:46 GMT
Hi All,
 
Is it not possible looking up the datasource in a session bean's
constructor?
 
Let's say I have a simple hello world session beam and trying to lookup
the datasource in the bean constructor as follows.
 
public HelloWorldBean() throws CreateException {
                        
  try {
            Context jndiCntx = new InitialContext();
            DataSource ds = (DataSource)
jndiCntx.lookup("java:comp/env/xmeta_defaultDS");
  } catch (Exception e) {
        String msg = e.getMessage();
        throw new CreateException(msg);
  } 
}
 
It doesn't work and throwing following exception 
 
javax.naming.NameNotFoundException: comp/env/xmeta_defaultDS
        at
org.apache.geronimo.naming.java.RootContext.lookup(RootContext.java:45)
        at javax.naming.InitialContext.lookup(InitialContext.java:361)
        at ejb.demo.HelloWorld.<init>(HelloWorld.java:38)
        at
ejb.demo.HelloWorld$$FastClassByCGLIB$$95ed802d.newInstance(<generated>)
        at net.sf.cglib.reflect.FastClass.newInstance(FastClass.java:91)
        at
org.openejb.EJBInstanceFactoryImpl.newInstance(EJBInstanceFactoryImpl.ja
va:76)
        at
org.openejb.sfsb.StatefulInstanceContextFactory.newInstance(StatefulInst
anceContextFactory.java:119)
        at
org.openejb.sfsb.StatefulInstanceFactory.createInstance(StatefulInstance
Factory.java:86)
        at
org.openejb.sfsb.StatefulInstanceInterceptor.getInstanceContext(Stateful
InstanceInterceptor.java:144)
        at
org.openejb.sfsb.StatefulInstanceInterceptor.invoke(StatefulInstanceInte
rceptor.java:92)
        at
org.openejb.transaction.ContainerPolicy$TxNotSupported.invoke(ContainerP
olicy.java:89)
        at
org.openejb.transaction.TransactionContextInterceptor.invoke(Transaction
ContextInterceptor.java:80)
        at
org.openejb.SystemExceptionInterceptor.invoke(SystemExceptionInterceptor
.java:82)
        at
org.openejb.GenericEJBContainer.invoke(GenericEJBContainer.java:238)
        at
org.openejb.server.ejbd.EjbRequestHandler.invoke(EjbRequestHandler.java:
297)
        at
org.openejb.server.ejbd.EjbRequestHandler.doEjbHome_CREATE(EjbRequestHan
dler.java:342)
        at
org.openejb.server.ejbd.EjbRequestHandler.processRequest(EjbRequestHandl
er.java:205)
        at org.openejb.server.ejbd.EjbDaemon.service(EjbDaemon.java:150)
        at org.openejb.server.ejbd.EjbServer.service(EjbServer.java:87)
        at
org.openejb.server.ejbd.EjbServer$$FastClassByCGLIB$$d379d2ff.invoke(<ge
nerated>)
        at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
        at
org.apache.geronimo.gbean.runtime.FastMethodInvoker.invoke(FastMethodInv
oker.java:38)
        at
org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(GBeanOperation.j
ava:118)
        at
org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(GBeanInstance.jav
a:800)
        at
org.apache.geronimo.gbean.runtime.RawInvoker.invoke(RawInvoker.java:57)
        at
org.apache.geronimo.kernel.basic.RawOperationInvoker.invoke(RawOperation
Invoker.java:36)
        at
org.apache.geronimo.kernel.basic.ProxyMethodInterceptor.intercept(ProxyM
ethodInterceptor.java:96)
        at
org.activeio.xnet.ServerService$$EnhancerByCGLIB$$fa602305.service(<gene
rated>)
        at org.activeio.xnet.ServicePool$2.run(ServicePool.java:67)
        at org.activeio.xnet.ServicePool$3.run(ServicePool.java:90)
        at
org.apache.geronimo.pool.ThreadPool$ContextClassLoaderRunnable.run(Threa
dPool.java:138)
        at
EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(Unknown
Source)
        at java.lang.Thread.run(Thread.java:570)
 
This is my openejb-jar.xml
 
<?xml version="1.0"?>
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar" 
configId="ejb-Demo" 
parentId="geronimo/j2ee-server/1.0/car">
 
<enterprise-beans> 
      <session>
         <ejb-name>HelloWorld</ejb-name>
         <jndi-name>HelloWorld</jndi-name>
         <resource-ref>
            <ref-name>xmeta_defaultDS</ref-name>
            <resource-link>jdbc/ASBDataSource</resource-link>
         </resource-ref>
      </session>
</enterprise-beans> 
</openejb-jar>
 
If I call the datasource lookup in a method other than constructor it
works fine.
What would you suggest to solve this problem? 
 
This works fine with WebSphere application server if I call the
datasource lookup in the constructor.
 
Thanks,
Siraj

Mime
View raw message