package com.util;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
return new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception to track it
System.err.println("SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public static void shutdown() {
// Optional but can be used to Close caches and connection pools
getSessionFactory().close();
}
}
我试图理解上面的代码。我是 Java 的初学者,很难具体理解以下行。这是否意味着,一个Configuration对象有一个配置方法,配置方法有buildSessionFactory方法?
return new Configuration().configure().buildSessionFactory();
慕盖茨4494581
慕哥6287543
相关分类