On Dec 2, 2006, at 2:57 PM, David Blevins wrote:
Hi Per, the data you've posted helps quite a bit. I think I have
your answer....
On Dec 2, 2006, at 12:55 AM, Per Newgro wrote:
I get the following exception
javax.naming.NameNotFoundException: Name "java:/APPLDB" not found.
at
org.openejb.core.ivm.naming.IvmContext.federate(IvmContext.java:184)
at org.openejb.core.ivm.naming.IvmContext.lookup
(IvmContext.java:147)
at javax.naming.InitialContext.lookup(InitialContext.java:
351)
if i do the following:
DataSource db = (DataSource) myInitialContext.lookup("java:/APPLDB");
Just a note on what I mention in my previous email below. The reason
"java:/APPLDB" works in JBoss is they are letting you lookup a
datasource you haven't declared a reference to in your ejb-jar.xml.
This is completely against the spec and results in non-portable
apps. I will note you can do this OpenEJB too -- we're not the kind
to tell you what you can and can't do. The name you use to lookup a
non-declared datasource is:
new InitialContext().lookup("java:openejb/connector/Default JDBC
Database");
or in your case:
new InitialContext().lookup("java:openejb/connector/APPLDB");
So we do support this non-standard practice, but we put it under
"java:openejb" so you are absolutely aware you are using a vendor
specific feature, rather than putting them at "java:/APPLDB" which
someone who doesn't read the spec everyday would totally think is a
fine, portable, thing to do when in fact it's a vendor lock-in.
We don't really encourage people to use it as there's little upside
in it for you, but it is supported. You'll notice that the path
"openejb/connector/[ConnectorName]" also matches the exact xml
structure of the openejb configuration file:
<openejb>
...
<Connector id="APPLDB">
...
You can actually lookup a number of things from the "java:openejb"
namespace, though we don't advertise it or really encourage it. But
you can if you like :)
-David
You've got everything you need except you'll want to add the ejb
spec required resource refs to your ejb-jar.xml file like so:
<session>
...
<resource-ref>
<res-ref-name>APPLDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<res-ref-name>APPLDBnoTx</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</session>
Then you'll be able to look them up from that bean via "java:comp/
env/APPLDB" and "java:comp/env/APPLDBnoTx"
On a slightly different note, I'm curious why you'd have two
connectors with the exact same configuration.
-David