-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problems overriding properties in hibernate.cfg.xml
PostPosted: Thu Jun 16, 2005 7:24 am 
Newbie

Joined: Thu Jun 16, 2005 7:00 am
Posts: 6
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.