首页 > Web开发 > 详细

Hibernate运行过程

时间:2016-10-11 14:36:00      阅读:172      评论:0      收藏:0      [点我收藏+]

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运行过程

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!