文档介绍:持久化对象生命周期
课程代码:
课程介绍
目的:掌握持久化对象的生命周期,Session对象的“脏”数据检查,Session接口的核心方法
内容:讲解持久化对象的生命周期,Session对象的“脏”数据检查和Session接口中的几个核心方法的使用
重点:持久化对象的生命周期
难点:Session对象的“脏”数据检查
持久化对象生命周期的状态
Transient状态
Guestbook gb = new Guestbook();
(“刘备");
(“liubei@");
("01082502282");
(new ());
("我喜欢这个网站");
Persistent状态
Session session = () .getCurrentSession();
Transaction tx = ();
Guestbook gb = new Guestbook();
(“刘备");
("liubei@");
("01082502282");
(new ());
("我喜欢这个网站");
(gb);
Detached状态
Session session = () .getCurrentSession();
Transaction tx = ();
Guestbook gb=(Guestbook)(, new Integer(1));
mit();
();
(“张飞");
Removed状态
Session session = () .getCurrentSession();
Transaction tx = ();
Guestbook gb=(Guestbook)(, new Integer(1));
(gb);
mit();
Session对象的“脏”数据检查
Persistent状态的对象受Session的管理,我们对对象的属性值的修改,在Session对象调用close()mit()方法之后,数据库中对应的数据也会跟着进行同步更新
Session session = () .getCurrentSession();
Transaction tx = ();
Guestbook gb = (Guestbook) (, new Integer(1));
(“张飞");
("01082502282");
mit();
Session接口的核心方法
saveOrUpdate()方法
Session session = () .getCurrentSession();
Transaction tx = ();
Guestbook gb = (Guestbook) (, new Integer(1));
mit();
(“张飞");
session = () .getCurrentSession();
tx= ();
(gb);
mit();