SessionFactory sessionFactory=HibernateUtil.getSessionFactory(); Session session=sessionFactory.getCurrentSession(); Student s = new Student(); s.setName("zt1"); s.setPassword("111111"); Transaction t = session.beginTransaction(); session.save(s); //s.setName("zt3");此时只发insert t.commit(); 控制台打印:Hibernate: insert into Student (name, password) values (?, ?) SessionFactory sessionFactory=HibernateUtil.getSessionFactory(); Session session=sessionFactory.getCurrentSession(); Student s = new Student(); s.setName("zt1"); s.setPassword("111111"); Transaction t = session.beginTransaction(); session.save(s); s.setName("zt3");//此时发insert后还有update t.commit(); 控制台打印: |
|
40分 |
session.save(s)后对象就已经是持久态了 ,你之后修改对象的属性当然会update了
|
如楼上所说,持久态的对象在修改时会发出update语句!
|
|
楼上说的有道理
|