1、三種狀態(tài)的區(qū)分關(guān)鍵在于
A、有沒有ID
B、ID在數(shù)據(jù)庫中有沒有
C、在內(nèi)存中有沒有(session緩存)
2、三種狀態(tài)說明
A、transient:內(nèi)存中一個(gè)對(duì)象,沒ID,緩存中也沒有
B、persistent:內(nèi)存中有,緩存中有,數(shù)據(jù)庫有(存在ID)
C、detached:內(nèi)存有,緩存沒有,數(shù)據(jù)庫有(存在ID)
TeacherPK pk = new TeacherPK();
pk.setId(4);
pk.setName("t1");
Teacher t = new Teacher();
t.setPk(pk);
t.setTitle("高級(jí)");
t.setBirthDate(new Date());
t.setStatus(Status.sNormal);
//t -> transient

Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
session.save(t);
session.getTransaction().commit();
//t -> persistent
System.out.println(t.getTitle());
//t -> detached
A、有沒有ID
B、ID在數(shù)據(jù)庫中有沒有
C、在內(nèi)存中有沒有(session緩存)
2、三種狀態(tài)說明
A、transient:內(nèi)存中一個(gè)對(duì)象,沒ID,緩存中也沒有
B、persistent:內(nèi)存中有,緩存中有,數(shù)據(jù)庫有(存在ID)
C、detached:內(nèi)存有,緩存沒有,數(shù)據(jù)庫有(存在ID)

















