It looks like in the Hibernate 3.3 source code that the data source was retrieved by the following code where jndiName is a string (from org.hibernate.connection.DatasourceConnection line 75)
Code:
ds = ( DataSource ) NamingHelper.getInitialContext( props ).lookup( jndiName );
In 4.1.0 it is done by the following where name is a javax.naming.Name (from org.hibernate.service.jndi.internal.JndiServiceImpl line 65)
Code:
public Object locate(String jndiName) {
InitialContext initialContext = buildInitialContext();
Name name = parseName( jndiName, initialContext );
try {
return initialContext.lookup( name );
}
catch ( NamingException e ) {
throw new JndiException( "Unable to lookup JNDI name [" + jndiName + "]", e );
}
finally {
cleanUp( initialContext );
}
}
If you make the following fix to the above code it will work.
Code:
return initialContext.lookup( name.toString() );
The Name object that it is using is a javax.naming.CompositeName which I think is the problem but I don't know why it is of that type.
The Name object is generated from line 86 in JndiServiceImpl
Code:
return context.getNameParser( "" ).parse( jndiName );