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!

4

1 回答 1

0

您必须将默认包放入源目录(无论其名称如何)中,以便 Eclipse 在编译时将其复制到目标文件夹,从而在执行应用程序时在类路径的根目录中可用。

于 2012-12-09T13:49:38.643 回答