MyEclipse

Software Development - how to load Hibernate.cfg.xml from classpath

pavanpinnu - Dec 06, 2007 - 05:43 AM
Post subject: how to load Hibernate.cfg.xml from classpath
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
support-nipun - Dec 06, 2007 - 05:36 PM
Post subject: RE: how to load Hibernate.cfg.xml from classpath
Moving to Off Topic >> Software Development.
pgirish007 - Dec 11, 2007 - 09:15 PM
Post subject: RE: how to load Hibernate.cfg.xml from classpath
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
All times are GMT - 6 Hours
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits