0

I use STS and i've created MVC template project. I want to use hibernate but i don't know where to put hibernate.cfg.xml. In default projects i just put it in src/ folder.

    static {

        try {

            // Create the SessionFactory from hibernate.cfg.xml
            //AnnotationConfiguration
            sessionFactory = new Configuration().configure().buildSessionFactory();

        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {

        return sessionFactory;

    }
}

I know that i can strictly add path to Hibernate.cfg.xml like that:

sessionFactory = new Configuration().configure("XXX").buildSessionFactory();

where XXX is the path to hibernate.cfg.xml. Where should i put hibernate.cfg.xml if i will use "/hibernate.cfg.xml" like path? Thanks!

Andrey Yaskulsky
  • 2,458
  • 9
  • 39
  • 81

1 Answers1

0

You must put in in the default package, in your sources directory (whatever it's named), so that Eclipse copies it to the target folder when compiling, which makes it available at the root of the classpath when the application is executed.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255