Skip to main content

Confused aboud create-jdbc-resource: can I use Java EE 6 JNDI namespaces?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
4 replies [Last post]
ljnelson
Offline
Joined: 2003-08-04

The documentation for creating JDBC resources (
http://docs.oracle.com/cd/E26576_01/doc.312/e24928/jdbc.htm#ggnda) says (in
part) this:

Because all JNDI names are in the java:comp/env subcontext, when specifying
> the JNDI name of a JDBC resource in the Administration Console, use only
> the jdbc/name format.

But I would like to create a JDBC resource that I may subsequently look up
using the following JDBC name (which is to my knowledge Java EE
6-compliant, according to section EE.5.2.2, and is *not* in the
java:comp/env subcontext but is instead global to the instance):

java:global/jdbc/H2Test

If I create this JDBC resource by hand-editing the domain.xml (boo, I
know), everything works fine:

(In this case testDatabaseDataSourceName is a System property that resolves
to "java:global/jdbc/H2Test", and the referenced connection pool has
already been created.)

If I create this JDBC resource (or try to) using create-jdbc-resource,
passing it "java:global/jdbc/H2Test", the command fails saying that JNDI
names cannot have ":" in them.

But if I do create-jdbc-resource and pass only jdbc/H2Test, then as I
understand it I'm really creating java:comp/env/jdbc/H2Test.

In case it matters, I'm creating a global data source for use during
embedded testing.

Any enlightenment greatly appreciated.

Thanks,
Laird

--
http://about.me/lairdnelson

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mvatkina
Offline
Joined: 2005-04-04

I'll leave the actual answer to our connector people, but did you try a
@DataSourceDefinition with your app?

-marina

Laird Nelson wrote:
> The documentation for creating JDBC resources
> (http://docs.oracle.com/cd/E26576_01/doc.312/e24928/jdbc.htm#ggnda)
> says (in part) this:
>
> Because all JNDI names are in the |java:comp/env| subcontext, when
> specifying the JNDI name of a JDBC resource in the Administration
> Console, use only the |jdbc/|name format.
>
>
> But I would like to create a JDBC resource that I may subsequently
> look up using the following JDBC name (which is to my knowledge Java
> EE 6-compliant, according to section EE.5.2.2, and is /not/ in the
> java:comp/env subcontext but is instead global to the instance):
>
> java:global/jdbc/H2Test
>
>
> If I create this JDBC resource by hand-editing the domain.xml (boo, I
> know), everything works fine:
>
> jndi-name="${testDatabaseDataSourceName}" />
>
>
> (In this case testDatabaseDataSourceName is a System property that
> resolves to "java:global/jdbc/H2Test", and the referenced connection
> pool has already been created.)
>
> If I create this JDBC resource (or try to) using create-jdbc-resource,
> passing it "java:global/jdbc/H2Test", the command fails saying that
> JNDI names cannot have ":" in them.
>
> But if I do create-jdbc-resource and pass only jdbc/H2Test, then as I
> understand it I'm really creating java:comp/env/jdbc/H2Test.
>
> In case it matters, I'm creating a global data source for use during
> embedded testing.
>
> Any enlightenment greatly appreciated.
>
> Thanks,
> Laird
>
> --
> http://about.me/lairdnelson
>

ljnelson
Offline
Joined: 2003-08-04

On Thu, Jul 26, 2012 at 2:05 PM, Marina Vatkina
wrote:

> I'll leave the actual answer to our connector people, but did you try a
> @DataSourceDefinition with your app?
>

No; I'm aware that's an option, though. It is a little "stronger" than I
want, though: I don't want my *application* to actually define this data
source; I want its *environment* to do so.

It looks like I can do it via glassfish-resources.xml. I'm curious,
though: if I can do it there, and if I can slide it past
create-jdbc-resource by hand-editing domain.xml, how come I can't do it
using create-jdbc-resource directly? What's so bad about a colon? :-)

Best,
Laird

--
http://about.me/lairdnelson

ljnelson
Offline
Joined: 2003-08-04

On Thu, Jul 26, 2012 at 2:23 PM, Laird Nelson wrote:

> On Thu, Jul 26, 2012 at 2:05 PM, Marina Vatkina > wrote:
>
>> I'll leave the actual answer to our connector people, but did you try a
>> @DataSourceDefinition with your app?
>>
>
> No; I'm aware that's an option, though. It is a little "stronger" than I
> want, though: I don't want my *application* to actually define this data
> source; I want its *environment* to do so.
>
> It looks like I can do it via glassfish-resources.xml. I'm curious,
> though: if I can do it there, and if I can slide it past
> create-jdbc-resource by hand-editing domain.xml, how come I can't do it
> using create-jdbc-resource directly? What's so bad about a colon? :-)
>

I've filed a bug here: http://java.net/jira/browse/GLASSFISH-18954

Best,
Laird

--
http://about.me/lairdnelson

mvatkina
Offline
Joined: 2005-04-04

Laird Nelson wrote:
> On Thu, Jul 26, 2012 at 2:05 PM, Marina Vatkina
> > wrote:
>
> I'll leave the actual answer to our connector people, but did you
> try a @DataSourceDefinition with your app?
>
>
> No; I'm aware that's an option, though. It is a little "stronger"
> than I want, though: I don't want my /application/ to actually define
> this data source; I want its /environment/ to do so.
>
> It looks like I can do it via glassfish-resources.xml. I'm curious,
> though: if I can do it there, and if I can slide it past
> create-jdbc-resource by hand-editing domain.xml, how come I can't do
> it using create-jdbc-resource directly? What's so bad about a colon? :-)

A colon can be a delimiter. Did you try '\:'?

-marina
>
> Best,
> Laird
>
> --
> http://about.me/lairdnelson
>