session 用法

//java 中 session 的初始化
    private Map<String,Object> session = ActionContext.getContext().getSession();



//hibernate中session的用法

//读取hibernate.cfg.xml文件
//Configuration 加载系统配置文件

    Configuration cfg = new Configuration().configure();
		
//创建SessionFactory,绑定数据库,一个数据库对应一个SessionFactory
    SessionFactory factory = cfg.buildSessionFactory();
    Session session = null;

//可以看成是对connection进行包装,还管理缓存
    session = factory.openSession();

//开启事务 Transaction
    session.beginTransaction();

//提交事务
    session.getTransaction().commit();

你可能感兴趣的:(java,Hibernate,xml,配置管理)