1.加入所需要的包
下载hibernate3.3.2的发行包,加入hibernate3.jar 和hibernate-distribution-3.3.2.GA\lib\required下的6个jar.
http://www.slf4j.org 网站上下载slf4j-1.5.8 加入slf4j-nop-1.5.8.jar
说明:在hibernate-distribution-3.3.2.GA\lib\required下的slfrj是接口,slf4j-nop-1.5.8.jar才是实现.
2.创建hibernate.cfg.xml文件,还有实体类的映射文件,这些在官方文档有详细说明,copy它们最不会出错...
3.创建SessionFactory辅助类,还是用官方文档里的.
package org.hibernate.tutorial.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, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
发现用javaeye来做笔记还不错^^,把以前学过的东西总结一下,以后查起来很方便.