facebook

Location of the hibernate.cfg.xml file [Closed]

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #219796 Reply

    I am trying to set up a project and Add Hibernate Capablities to my project. The “wizzard” only lets me put the hibernate.cfg.xml file in the “src” directory.

    I am trying to put in under the “WEB-INF” directory with the other struts-conf.xml file and several other configuration files. I browse to the “/WebRoot/WEB-INF” folder and select it and receive a “the specified path does not exist in this workspace.” But that path most certainly does exist….

    I can change it my manually moving the hibernate.cfg.xml file to that workspace, but I haven’t tried updating it through XDoclet, yet. So, I don’t know the ramifications of that.

    Since the “src” folder is not going to be deployed to the server… Why does MyEclipse force me to put the hibernate.cfg.xml file there. Specifications state it has to be in my classpath… What gives?

    #219802 Reply

    Riyad Kalla
    Member

    The file is suppose to go into the root of your /src dir, while /src is not deployed, everything in it is built/copied out to WEB-INF/classes which IS deployed. Hibernate needs the cfg.xml file in the classpath of your project to load its config settings, your WEB-INF dir is not in your classpath, so if you were to put it there, you’d be ‘hiding’ it from Hibernate and it wouldn’t work.

    #219999 Reply

    Actually if the config file is not in the class path, you can pass the info to it at initialization time…. Directly from “Hibernate In Action” …

    
    SessionFactory sessions = new Configuration().configure("/WEB-INF/hibernate.cfg.xml").buildSessionFactory();
    

    I’ve tried this and it works….

    I try to keep all my configuration files together, it makes for easier maintenance, documentation and version control (if you keep configuration files in version control).

    Stephen McConnell

    #220000 Reply

    Riyad Kalla
    Member

    I stand corrected, thx for the info!

    #221907 Reply

    dhonig
    Member

    Just to clarify…I don’t have hibernate in action available, so I am guessing you are setting the config from inside a servlet and that just happens to work from inside a servlet with the web container your using or are there some other details you could provide that explain why this works?…..

    In JBoss the classloader does not recognize that….You would have to do a bit of monkeying around, but I am guessing it might work from a servlet class that is specified in web.xml….?

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Location of the hibernate.cfg.xml file [Closed]

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