Hibernate.cfg.xml path

I have a java project and I am using hibernate. Here I want to put the hibernate.cfg.xml file outside the src folder, but when I configure this file, it shows a FileNotFoundException. If I put it in the src folder, that's fine. But I want to separate java src and the whole configuration file in a separate folder.

                               root
                                |____src
                                |____conf
                                      |____mapping
                                             |____(all xml file with hibernate.cfg.xml)

SessionFactory _sessionFactory = (new configuration ()). configure ("./conf/mapping/hibernate.cfg.xml"). buildSessionFactory ();

His exponential exception ...

+3
source share
2 answers

Add the conf / mapping directory to yours CLASSPATHand upload the configuration file

new Configuration().configure("/hibernate.cfg.xml").buildSessionFactory();

or simply

new Configuration().buildSessionFactory();

since it is a standard name.

, ./.

+1

,

  • conf/mapping project build path ( Eclipse properties->javabuild path->source->add Folder)
  • hibernate new Configuration().buildSessionFactory();

.

0

All Articles