facebook

how to load Hibernate.cfg.xml from classpath

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #279389 Reply

    pavanpinnu
    Member

    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

    #279409 Reply

    Loyal Water
    Member

    Moving to Off Topic >> Software Development.

    #279565 Reply

    Girish Pandit
    Participant

    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

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: how to load Hibernate.cfg.xml from classpath

You must be logged in to post in the forum log in