kgignatyev wrote:
It is possible to programmatically tweak Hibernate configuration before creating session factory. For example
configuration = new Configuration();
configuration
.configure( getConfigurationName() ).
setProperty( "jndi name for data source" , Productionname);
sessionFactoryProduction = configuration.buildSessionFactory();
setProperty( "jndi name for data source" , trest_name);
sessionFactoryTest = configuration.buildSessionFactory();
etc.
Thanks for the reply. I'm not using JNDI -- my cfg.xml file uses the "connection.url" property. I tried doing something like you mentioned (remove that property from the cfg.xml file, set it programmatically), but Hibernate always crashed when loading it (it crashed on the C3P0 configuration).
I got around the problem by having three complete hibernate.cfg.xml files, with the only difference being the database specified in the connection.url property. I then wrote a version of the HibernateUtils class (from the reference documentation) that maintains a HashMap of SessionFactory objects, one per database, with the key being the database name and the value being the SessionFactory. I changed getSessionFactory() to getSessionFactory(String dbName), and this method now looks up the correct SessionFactory when given the database name. If the SessionFactory isn't in the HashMap, it instantiates a new one and does configure(cfgXmlFileName), then adds it to the HashMap.
This all works, but it's pretty ugly.