Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in loading the config file manually.

 
Thillai Sakthi
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am using was5.1 and hibernate. Since I am using two different dbs, have configured two different .cfg.xml files - test1.cfg.xml and test2.cfg.xml. The problem is where do I place these files and how do I locate them programmatically for getting the config parameters ?
I have placed them in web-inf/classes folder, and tried looking up using

but it throws FilenotfoundException....


Have tried various other combinations too....all are failing....
Any ideas please?

Thanks in advance.......
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate just uses java.io to load the file like this I think. Remember that creating a file with the new File(filename) constructor doesn't behave like the classLoader.getResourceAsStream(String resourcename). The later will traverse the classpath looking for the resource, the former won't. So your config files need to be in the same folder as the class that is trying to load it (unless you supply an absolute path).

One way round this (which is acceptable since once you have configured your ORM layer it remains fairly static) is to actually configure it in code. i.e.
 
Thillai Sakthi
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul. I saw Configuration.java of hibernate's code and then I tried this

it worked fine. I placed the xml file under web-inf/classes
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic