You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by rde8026 <rd...@gmail.com> on 2008/09/20 00:10:29 UTC

HELP! JNDI DataSource Name

Hello,

I'm sorry to post to message; I've seen a bunch of messages like this posted
but everything I've read and tried doesn't seem to work and I have no idea
why.....

I'm trying to get a reference to a Container Managed DataSource (configured
in my openejb.xml file).  I can get the reference via the @Resource
annotation but I am unable to get the resource via standard JNDI.

here is my code




Object obj1 = new
javax.naming.InitialContext().lookup("java:openejb/Resource/JTADS");
I've also tried it like this:
Properties props = new Properties();
props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
javax.naming.Context ctx = new javax.naming.InitialContext(props);
Object obj1 = ctx.lookup("java:openejb/Resource/JTADS");

I always get this error: NameNotFoundException: Name
"java:openejb/Resource/JTADS" not found.

Now the reason I need to understand the correct JNDI name is so I can use it
as a Hibernate Property (hibernate.connection.datasource).

I'm using openejb 3.1 SNAPSHOT and Hibernate hibernate-3.2.5.ga.

Any ideas?  I'm totally lost...as I understand it this should just work...
Thanks in advance....



-- 
View this message in context: http://www.nabble.com/HELP%21-JNDI-DataSource-Name-tp19579867p19579867.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: HELP! JNDI DataSource Name

Posted by David Blevins <da...@visi.com>.
On Sep 19, 2008, at 5:10 PM, rde8026 wrote:

> Object obj1 = new
> javax.naming.InitialContext().lookup("java:openejb/Resource/JTADS");
> I've also tried it like this:
> Properties props = new Properties();
> props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.LocalInitialContextFactory");
> javax.naming.Context ctx = new javax.naming.InitialContext(props);
> Object obj1 = ctx.lookup("java:openejb/Resource/JTADS");
>
> I always get this error: NameNotFoundException: Name
> "java:openejb/Resource/JTADS" not found.
>
> Now the reason I need to understand the correct JNDI name is so I  
> can use it
> as a Hibernate Property (hibernate.connection.datasource).
>
> I'm using openejb 3.1 SNAPSHOT and Hibernate hibernate-3.2.5.ga.
>
> Any ideas?  I'm totally lost...as I understand it this should just  
> work...
> Thanks in advance....

If hibernate is getting used in the context of an EJB, one technique  
that might work is to declare an @Resource reference to the datasource  
at the top of that bean's class.  That will cause it to be available  
to any code executing in the scope of that ejb via that name in JNDI.

As far as accessing java:openejb, I think we need to revise our code  
here.  Without going into too many details, the java:openejb isn't  
available in all situations.  It's really only available when doing a  
"new InitialContext().lookup("java:openejb")" from outside the scope  
of an ejb or servlet (say in a test case).  From inside the scope of  
an ejb or servlet you get their private JNDI scope which doesn't  
include java:openejb (it should).  When doing a lookup via "new  
InitialContext(properties).lookup("java:openejb)" with the properties  
listing the LocalInitialContextFactory you get an ejb-only namespace  
where java:openejb isn't there (again, it should).  We need to fix up  
those namespaces.

Trying roll a 3.1 release at the moment, but this is definitely  
something we'll fix up immediately after.  And hopefully get a 3.1.1  
out very soon after 3.1.

-David