-->
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.  [ 6 posts ] 
Author Message
 Post subject: Can you specify *.xml files in your own location?
PostPosted: Tue Jun 07, 2005 10:25 am 
Newbie

Joined: Fri Jun 03, 2005 4:16 am
Posts: 3
Hi guys,

I am new to Hibernate and have done a search on this but have found loads of other (useful) tips and advice but not for what I need.

Basically I was wondering if it's possible to specify another location for the hibernate.cfg.xml file rather than the main class path of the project.

The reason is, when I compile up my code and export it as a jar file, I have the hib xml file in there - with all the settings for the specifc environment I'm working on (i.e., UAT or SIT or DEV or PRD). I really hate having to manually alter the hib xml for a specific region and re-exporting the compiled code. I'd much rather have the hib xml file external in a common /config dir and edit it externally.

But all my attempts at trying to manually specify the hib xml file in a place of my choice fail with the exceptions complaining it cannot find the hib xml file.

At the moment I am using the following which works fine - but I have to keep my hib xml file in the default project path:

Code:
SessionFactory sf = new Configuration().configure().buildSessionFactory();


Is what I want possible? If so, does someone have a working example of code they could post?

Or if I am reiterating a dead topic could someone please point me in the right thread direction?

Many thanks and apologies if this is an old subject.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 11:22 am 
Newbie

Joined: Mon Jun 06, 2005 9:38 am
Posts: 4
Did you try passing the path as an argument to the configure() method


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 11:46 am 
Newbie

Joined: Fri Jun 03, 2005 4:16 am
Posts: 3
Yes I did - I passed in, for example "c:\\myapp\\config\\hibernate.cfg.xml" but it complained not only that it couldn't find the hibernate.properties file but then threw up majorly when it came to locating the hib xml file.

I tried adding a new File("blah blah") object in there.. I think i tried a load of different approaches.

At the moment it's not a "critical" issue for me - it's just a bit annoying that I need to have 3 different hibernate.cfg.xml files in my project root:

Code:
hibernate.cfg.xml
hibernate.cfg.xml.uat
hibernate.cfg.xml.sit
hibernate.cfg.xml.dev
hibernate.cfg.xml.prd


And depending on which env I deploy the code to, have to first rename the appropriate xml file for the right place.

Out of curiousity, what would you do?


Top
 Profile  
 
 Post subject: answer
PostPosted: Tue Jun 07, 2005 12:00 pm 
Newbie

Joined: Fri Apr 22, 2005 3:39 pm
Posts: 18
IMHO you should use programmatic configuration of the session, not via hibernate.cfg.xml + configure(). You can add every mapping to the session programmaticaly, set every property. In may case, I do not have hibernate.cfg.xml at all and use this approach to connect to 2 different dbs with the same structure and same set of hbm.xml mappings.

Cheers!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 12:04 pm 
Newbie

Joined: Fri Jun 03, 2005 4:16 am
Posts: 3
Ahhhhh - I can't believe I didn't think of that!

I just realized that I even have test code that set all the req'd properties programatically when I couldn't get the XML loaded! Sheesh!

Thanks Mike!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 12:14 pm 
Newbie

Joined: Mon Jun 06, 2005 9:38 am
Posts: 4
May be I would put these cfg files for different environments together and depending on the environment programatically choose the appropriate config file.
Chapter 3 of the reference documentation has some details.

By the way did you try relative file paths for the config files.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.