-->
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.  [ 5 posts ] 
Author Message
 Post subject: Is it possible to have multiple hibernate.properties files?
PostPosted: Fri Oct 17, 2003 2:45 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Is it possible to have multiple hibernate.properties files?
Or, is there another (better?) way to accomplish the same thing?

I know I can have multiple hibernate.cfg.xml files (and I do) but I would also like to have multiple properties files (or avoid using the main one in certain scenarios).

The reason I ask is because I need to have a different setup for running unit tests than for running in a container but all of my code is in the same package structure and when my unit test sets up the Hibernate config tries to use a property from the main hibernate.properties file which is only valid for running in the container.

Thank-you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2003 3:57 pm 
Beginner
Beginner

Joined: Wed Oct 15, 2003 3:08 pm
Posts: 32
What about having a hibernate.properties.production and hibernate.properties.test. Then you can have an ant task that copies the hibernate.properties.test to hibernate.properties when running tests. But when building production code it instead copies hibernate.properties.production?


Top
 Profile  
 
 Post subject: solution
PostPosted: Fri Oct 17, 2003 5:10 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Thank-you for the suggestion,
Here is what I found (and did) in case anyone else is interested:
Code:
URL configFileURL = Class.class.getResource(TEST_CONFIG_PATH);
BufferedInputStream bis = new BufferedInputStream(Class.class.getResourceAsStream(TEST_PROPERTIES_PATH));
Properties properties = new Properties();
properties.load(bis);
bis.close();

Configuration configuration = (new Configuration().setProperties(properties)).configure(configFileURL);
SessionFactory factory = configuration.buildSessionFactory();

It seems to work nicely for me.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2003 9:39 pm 
Regular
Regular

Joined: Fri Sep 05, 2003 12:01 am
Posts: 80
Location: Bogot
Quote:
Here is what I found (and did) in case anyone else is interested:



If you decide (someday) to use XML config instead of the properties file check this method:


http://hibernate.bluemars.net/hib_docs/api/net/sf/hibernate/cfg/Configuration.html#configure(java.lang.String)[/url]

_________________
Mauricio Hern


Top
 Profile  
 
 Post subject: .properties vs. .xml
PostPosted: Fri Oct 17, 2003 9:45 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Yes, thank-you, I suppose I could add everything to the .cfg.xml file.
I just wanted to use the existing properties file with a couple changes rather than having to fill in everything I wanted as xml.
It works the way I have it which required the least amount of typing.

Thanks


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

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.