hibernateutil.java
来自「是Eclipse web开发从入门到精通的源码」· Java 代码 · 共 31 行
JAVA
31 行
package library.main;
import java.io.File;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
File file = new File(
"E:\\Eclipsebook\\eclipse\\workspace\\Library\\src\\hibernate.cfg.xml");
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure(file)
.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;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?