Hibernate操作数据库的7个步骤

hibernate操作数据库的7个步骤:

1  读取并解析配置文件

    Configuration conf = new Configuration().configure();

2 读取并解析映射信息,创建SessionFactory

   SessionFactory sf  = conf.buildSessionFactoty();

3 打开Session

  Session session = sf.openSession;//sf.getCurrentSession();

扫描二维码关注公众号,回复: 759071 查看本文章

4 开始一个事务(增删改操作必须,查询操作可选)

  Transaction tx = session.beginTransaction();

5 数据库操作

 session.sava();

6 提交事务(回滚事务)

 tx.commit();(tx.rollback();)

7 关闭session

 session.close();

猜你喜欢

转载自bao1073740756-126-com.iteye.com/blog/1290545