Hibernate在资源文件夹中找不到配置文件

时间:2018-12-11 21:06:28

标签: java xml hibernate jdbc

尽管资源文件夹中没有位置,Hibernate也无法找到cfg.xml。如何设置hibernate.cfg.xml的路径?

工厂类:

public class HibernateSessionFactoryUtil {
private static SessionFactory sessionFactory;

private HibernateSessionFactoryUtil() {}

public static SessionFactory getSessionFactory() {
    if (sessionFactory == null) {
        try {
            Configuration config = new Configuration().configure();
            ServiceRegistry serviceRegistery = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();
            SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistery);
        } catch (Exception e) {
            System.out.println("Exception!!!   " + e);
        }
    }
    return sessionFactory;
}

要点:

public class Main {
public static void main(String[] args) {
    Session session = HibernateSessionFactoryUtil.getSessionFactory().openSession();
}

exception message

0 个答案:

没有答案