Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
pavanpinnu
Post subject: how to load Hibernate.cfg.xml from classpath  PostPosted: Dec 06, 2007 - 05:43 AM



Joined: Dec 06, 2007
Posts: 2

Hi all,

my hibernate.cfg.xml is configured to load the Database from a database pool with JNDI reference and the container is Tomcat 6.0.

every thing is working fine. But the problem is with Testing (Struts which user hibernate for DB interactions).

i implemented MockStrutsTestCase to test my Struts which needs no container. In the development environment, i changed the hibernate.cfg.xml from JNDI connection to hard coded values for DB connection and works fine.

my requirement is, i need to write the ant script, to test these test cases and if works fine, i need to make a war file and deploy in container.

now, the hibernate.cfg.xml is configured to JNDI connection, which in turns, getting fail in MockStrutsTestCase (as, it cant maintain the DB POOL).

i maintain a copy of hibernate.cfg.xml in other directory with hard coded values and put this directory in classpath first and then classes directory in classpath later.

but Hibernate API is not loading the hibernate.cfg.xml in classpath order and loading from classes directory directly.

how to resolve this issue.

Thanks in advance.

Regards
Pavan
 
 View user's profile Send private message  
Reply with quote Back to top
support-nipun
Post subject: RE: how to load Hibernate.cfg.xml from classpath  PostPosted: Dec 06, 2007 - 05:36 PM
Registered Member
Registered Member


Joined: Apr 18, 2007
Posts: 7497

Moving to Off Topic >> Software Development.

_________________
Nipun
MyEclipse Support
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
pgirish007
Post subject: RE: how to load Hibernate.cfg.xml from classpath  PostPosted: Dec 11, 2007 - 09:15 PM
Registered Member
Registered Member


Joined: Dec 04, 2007
Posts: 24

Loading of the hibernate.cfg.xml depends on how are you are calling "configuration.configure()" if you are not passing any parameter to .configure() method, then it would look for the file at WEB-INF/classes directory, means root of the classpath but if you want to pull out xml file from different location under same project then you can do something like "URL u = ClassLoader.getSystemResource(configFile);configuration.configure(u);" where configFile is a String object containing the location of the xml file.

-Girish
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits