pilhuhn wrote:
Do you have an example on how to integrate it in jboss-service.xml ?
Or do I need to add a hibernate.properties file somewhere (where?)
Thanks
Heiko
To be able to store the configuration in JNDI in Jboss, you have
to modify the existing HibernateService. Unfortunately, it
is not easy to extend this class as it contains package
method that you have to copy in order to be able to access
them. To store the configuration, it is needed to redefine the
buildSessionFactory method to add the binding of the
configuration and the start method to call the new method.
I include some of my methods.
Code:
protected String getConfigurationJndiName() {
return getJndiName() + "Configuration";
}
/**
* Create and bound the session factory and the configuration in JNDI.
*
* @return a <code>SessionFactory</code> value
* @exception HibernateException if an error occurs
*/
protected SessionFactory buildSessionFactory() throws HibernateException {
log.info( "Starting service at JNDI name: " + getJndiName() );
log.info( "Service properties: " + getProperties() );
Configuration cfg = new Configuration().addProperties( getProperties() );
String[] mappingFiles = parseResourceList( getMapResources() );
for ( int i=0; i<mappingFiles.length; i++ ) {
cfg.addResource( mappingFiles[i], Thread.currentThread().getContextClassLoader() );
}
try {
InitialContext context = NamingHelper.getInitialContext( getProperties() );
log.debug("Binding the configuration under the name " +
getConfigurationJndiName());
NamingHelper.bind(context, getConfigurationJndiName() , cfg);
} catch (NamingException e) {
throw new HibernateException(e);
}
return cfg.buildSessionFactory();
}
I hope this helps.