码迷,mamicode.com
首页 > Web开发 > 详细

Hibernate运行过程

时间:2016-10-11 14:37:23      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:java   hibernate   

Hibernate运行过程:

1.通过Configuration().configure();读取并解析hibernate.cfg.xml配置文件

2.由hibernate.cfg.xml中的<mappingresource="com/dr953393/Object.hbm.xml"/>读取并解析映射信息

3.通过config.buildSessionFactory();//创建SessionFactory

4.sessionFactory.openSession();//打开Sesssion

5.session.beginTransaction();//创建事务Transation

6.persistent operate持久化操作 //一般指Save这个方法

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

8.关闭Session

9.关闭SesstionFactory



// 创建服务注册对象

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

// 创建会话工厂对象

sessionFactory = config.buildSessionFactory();

// 会话对象

session = sessionFactory.openSession();

// 开启事务

transcation = session.beginTransaction();


Students student = new Students(2, "test2", new Date(),new Address("01066661234","100060"));

session.save(student);

//session.update(student);

//session.delete(student);


transcation.commit();// 提交事务

session.close();// 关闭会话

sessionFactory.close();// 关闭会话工厂

System.out.println("finished");




本文出自 “冰壁の邪神宫” 博客,请务必保留此出处http://dr953393.blog.51cto.com/1968164/1860541

Hibernate运行过程

标签:java   hibernate   

原文地址:http://dr953393.blog.51cto.com/1968164/1860541

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!