Is it possible to override properties in hibernate.cfg.xml with properties in a hibernate.properties file, like this?
------------C O D E S T A R T-----------------------------------------
SessionFactory factory;
Properties hibernateProperties = some valid property file
Configuration cfg = new Configuration();
if( null != hibernateProperties ) {
cfg = cfg.setProperties( hibernateProperties );
}
try {
cfg.configure();
factory = cfg.buildSessionFactory();
} catch ( HibernateException he ) {
// do something
}
-------------C O D E E N D-------------------------------------------
My hibernate.cfg.xml looks like this:
<property
name="hibernate.show_sql">false</property>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.url">jdbc:hsqldb:.</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.dialect">net.sf.hibernate.dialect.HSQLDialect</property>
My hibernate.properties looks like this:
hibernate.show_sql=false
hibernate.connection.driver_class=org.postgresql.Driver
hibernate.connection.url=jdbc:postgresql://localhost:5432/some_instance
hibernate.connection.username=some_username
hibernate.connection.password=some_password
hibernate.dialect=net.sf.hibernate.dialect.PostgreSQLDialect
Scenario:
When I execute cfg = cfg.setProperties( hibernateProperties ); I can see properties from my hibernate.properties, but when the cfg.configure() is executed, all my previous properties are gone.
Questions:
1. Am I not supposed to run cfg.configure()?
2. Am I supposed to execute the cfg = cfg.setProperties( hibernateProperties ); AFTER the cfg.configure();?
3. Do I misunderstand the whole property-thing here?
|