-
1. Re: **Programatically** attach DataSource to JNDI
juha Oct 1, 2003 6:02 PM (in response to themax)Just guessing, is that datasource implementation serializable?
-- Juha -
2. Re: **Programatically** attach DataSource to JNDI
juha Oct 1, 2003 6:04 PM (in response to themax)umm, nevermind the above, you're doing the lookup straight after you bound it in the same VM
-
3. Re: **Programatically** attach DataSource to JNDI
juha Oct 1, 2003 6:14 PM (in response to themax)But still... you might have to use NonSerializableFactory.rebind() to bind the DS if it's not serializable, the JBoss naming is doing this with its bind() implementation:
public void bind (Name name, Object obj) throws NamingException { Hashtable refEnv = getEnv (name); checkRef (refEnv); try { String className; // Referenceable if (obj instanceof Referenceable) obj = ((Referenceable)obj).getReference (); if (!(obj instanceof Reference)) { className = obj.getClass ().getName (); // Normal object - serialize using a MarshalledValuePair obj = new MarshalledValuePair(obj); } else
that should have thrown an IO exception which in turn should have been converted to a Naming Exception...?
-- Juha -
4. Re: **Programatically** attach DataSource to JNDI
themax Oct 2, 2003 1:48 AM (in response to themax)The class is definitely Serializable alright.. I have a check for that in the original code:
if ( ! ( ds instanceof Serializable ))
{
if ( log.isErrorEnabled ())
log.error ("The Datasource class '" + ds.getClass().getName() + "' is NOT Serializable");
}
(using Commons logging, with the priority set to "Debug" or "info", so I always see "error")
I'm also seeing a *possible* explanation in a TomCat Servlet init bug (where my code is fired from).. will check this out, and report back..
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10948 -
5. Re: **Programatically** attach DataSource to JNDI
themax Oct 2, 2003 3:02 AM (in response to themax)No joy.. I changed the code to be user-initiated (after the Servlet init), a new (non-null) Datasource was re-bound, but the same issue arose: the lookup (the next line of code after the bind) returned null.. so it look like the TomCat Servlet init bug is NOT my issue (or else there is a similar bug applicable to lookups outside the Servlet init).
Will check out the "Referenceable" references (forgive the pun) mentioned in earlier replies.
Thanks!
Colm -
6. Re: **Programatically** attach DataSource to JNDI
themax Oct 2, 2003 4:22 AM (in response to themax)If I switch the class being bound to a fairly straightforward Test class (implements EntityBean, Serializable), and try the rebind and lookup outside the init (haven't tried it from inside the init yet), it works (I get the actual instance back, as opposed to getting null back), which suggests that the issue is either related to the Sybase DataSource hierarchy, or that particular Sybase DataSource class itself.. will try a different type of DataSource (MySQL, or something), and see if the issue can be reproduced.