Location of hibernate.cfg.xml in project?

前端 未结 10 1781
盖世英雄少女心
盖世英雄少女心 2020-11-27 07:28

I created a project with following structure:

\"enter

HibernateUtil:



        
10条回答
  •  眼角桃花
    2020-11-27 07:44

    Give the path relative to your project.

    Create a folder called resources in your src and put your config file there.

       configuration.configure("/resources/hibernate.cfg.xml");
    

    And If you check your code

    Configuration  configuration = new Configuration().configure( "C:\\Users\\Nikolay_Tkachev\\workspace\\hiberTest\\src\\logic\\hibernate.cfg.xml");
    return new Configuration().configure().buildSessionFactory();
    

    In two lines you are creating two configuration objects.

    That should work(haven't tested) if you write,

    Configuration  configuration = new Configuration().configure( "C:\\Users\\Nikolay_Tkachev\\workspace\\hiberTest\\src\\logic\\hibernate.cfg.xml");
    return  configuration.buildSessionFactory();
    

    But It fails after you deploy on the server,Since you are using system path than project relative path.

提交回复
热议问题