3

I have a java project and I am using hibernate.The thing here is I want to place the hibernate.cfg.xml file outside "src" folder, but when I am configuring this file it is showing FileNotFoundException. If I put it inside src folder its ok. But I want to separate the java src and all config file in separate folder.

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

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

Its showing exception......

Arat Kumar rana
  • 187
  • 1
  • 5
  • 19

2 Answers2

1

Add conf/mapping directory to your CLASSPATH and load the configuration file

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

or just

new Configuration().buildSessionFactory();

as this is the standard name.

Regardless there would be no ./ at the beginning of the resource path.

gliptak
  • 3,592
  • 2
  • 29
  • 61
0

What you want to do is

  • include conf/mapping in your project build path(With Eclipse properties->javabuild path->source->add Folder)
  • then no need to precise the hibernate config file in your code new Configuration().buildSessionFactory(); is enough

This manipulation is simple and works like a charm.

william.eyidi
  • 2,315
  • 4
  • 27
  • 39