(1)hibernate3.3.2准备工作

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来做笔记还不错^^,把以前学过的东西总结一下,以后查起来很方便.

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值