Why not use the same JNDI name on all stages?If that is not an option.. have you tried doing the lookup on the resource-ref yourself. I am not sure, what that would give you in return (a string with the _actual_ JNDI name to use)? What I have been successfully doing is adding properties to the hibernate configuration at runtime, when using a session factory. For your problem, this could look something like this:
Code:
// read hibernate configuration file
HIBERNATE_CONFIG = new Configuration();
HIBERNATE_CONFIG.configure(HIBERNATE_CONFIG_FILE);
// add (or modify) your own properites at runtime
Properties properties = new Properties();
properties.put("hibernate.connection.datasource", dataSourceName);
HIBERNATE_CONFIG.addProperties(properties);
// create session factory
SESSION_FACTORY = HIBERNATE_CONFIG.buildSessionFactory();
Now, if you can lookup the
dataSourceName from JNDI or if you can read it from a stage property file, you have almost build what hibernate should do on its own or rather what WebSphere should provide.