我与同事发生冲突。
假设我们在Hibernate中实现Short-Lived-Sessions。我的意思是
public int createUser(String eMail){
User u = new User();
u.setEMail(eMail);
em.persist(u);
return u.getUserId();
}
// time to think.
public void changeUserEMail(int userId, String newEMail){
User user = (User) em.find(User.class, userId);
user.setEMail(newEMail);
em.persist(user);
}
是Short-Lived-Sessions。 Whearat my colleague意思是:
public User createUser(String eMail){
User user = new User();
user.setEMail(eMail);
em.persist(user);
return user;
} // detach after call
// time to think
public void changeUserEMail(User user, String newEMail) {
em.merge(user); // attach
user.setEMail(eMail);
em.persist(user);
} // detach after call
也是Short-Lived-Session。
谁更正对?