完成本教程
“会话结束后,持久性对象设置为分离对象”
我的问题是如果您在第一次提交后但在关闭会话之前开始另一个事务会发生什么。此时用户对象处于什么状态?
public static void main(String[] args) {
System.out.println("Maven + Hibernate + Oracle");
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
DBUser user = new DBUser(); //creating transient object
user.setUserId(104);
user.setUsername("user1");
user.setCreatedBy("system");
user.setCreatedDate(new Date());
session.saveOrUpdate(user); //Updating the transient object to persistence object
session.getTransaction().commit();
session.beginTransaction();
user.setUsername("user2"); //what state is user object in right now?
session.saveOrUpdate(user);
session.getTransaction().commit();
session.close();
}