I am wondering how people have implemented Hibernate to work on different database environments, without having to recompile the code.
What we have done, is to create a jar with the “hibernate.cfg.xml” , “*.hbm.xml” files and java code included, but at the moment, if we want to move to a different environment (i.e. Development to Test or Production), we would have to recompile the code (or at least re-jar the code with the different hibernate.cfg.xml).
Are there any document or notes about configurations on the fly or can someone suggests how they have managed this.
Hibernate version: 3.1.3
the hibernate.cfg.xml:
Code:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.url">
jdbc:inetdae7:{server}:{server port}?database={database}
</property>
<property name="connection.driver_class">
com.inet.tds.TdsDriver
</property>
<property name="connection.username">{username}</property>
<property name="connection.password">{password}</property>
<property name="show_sql">true</property>
<property name="connection.pool_size">-1</property>
<property name="cache.provider_class">
org.hibernate.cache.NoCacheProvider
</property>
<property name="current_session_context_class">thread</property>
<property name="hbm2ddl.auto">update</property>
<property name="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<mapping
resource="project/data/schema/User.hbm.xml" />
<mapping
resource="project/data/schema/Group.hbm.xml" />
</session-factory>
</hibernate-configuration>
reason for "jar"ing the hibernate code is that many system will use the same jar.