问题描述:

I am in conflict with a colleague.

Assuming we implement Short-Lived-Sessions in Hibernate. I mean

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);

}

is Short-Lived-Sessions. Whearat my Colleague mean:

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

is Short-Lived-Session too.

Who is more right?

相关阅读:
Top