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: hibernate.cfg.xml in jar file how do I read it.
PostPosted: Thu May 25, 2006 4:48 pm 
Newbie

Joined: Thu May 25, 2006 4:38 pm
Posts: 3
Hibernate version: 3

I know this has probably been covered a 1000 times, but I can not seem to find the right keywords to pull up any info on the subject. Basically I need to find a way to read a configuration file + map files out of a jar. I have a project that communicates with several databases. I need to create a configuration and Session Factory for each of these databases. Currently each one has a config file as well as its maps / objects in its own jar files. I can get the Configuration to read from a directory but it does not search jarred directories in the class path. Is there a way to tell it the config is in xyz.jar (preferably by just the jar name or a relative path).

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 5:33 pm 
Regular
Regular

Joined: Mon May 22, 2006 2:30 pm
Posts: 74
If the files are in the classpath, hibernate should be able to find them. If they are in a jar file that is included in the class path, that implies they are at the top level of the jar file, not embedded in some path within the jar file. Is that the problem you are having?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 9:44 am 
Newbie

Joined: Thu May 25, 2006 4:38 pm
Posts: 3
The Jar is in the class path and the config file is buried within the jar in say com.bla.hibernate.cfg.xml if I execute the following line cfg.configure(“com/bla/hibernate.cfg.xml”).buildSessionFactory(); it does not find the configuration. The config file + mappings + Objects are in the jar. I have tried moving the config file to the root of the JAR but I still cannot get it to load the config.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 10:42 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Hi,

Code:
cfg.configure(“com/bla/hibernate.cfg.xml”)


should work. Are you sure you have the relevant jar in your classpath ?
Can you load other classes from this jar ?

_________________
dont forget to rate !


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 3:40 pm 
Newbie

Joined: Thu May 25, 2006 4:38 pm
Posts: 3
It is defiantly in the class path. I can construct instances of the classes that are in the jar. I decided to circumvent the whole process by just creating my configuration in code and adding the classes programmatically to the configuration. This works and it allows me to use two separate configurations in my code. I use JNDI so hardcoding it in code is no big deal but I would still like to know why it is not working as expected. I am sure it is something I was doing but I cannot see anything wrong. Both configurations work independently but when I try to use a URL string to locate them it will not locate the configuration in the jar.


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.