我需要将@Transactional 注释添加到第二种方法吗?我认为不是,但真的不确定。
@Transactional
public void addUser(User u) {
u.setCreationDate(new Date());
userDAO.addUser(u);
}
// should I add @Transactional annotation here?
public User addUser(String name, String surname) {
User user = new User();
user.setName(name);
user.setSurname(surname);
this.addUser(user);
return user;
}
// DAO method
public void addUser(User u) {
entityManager.persist(u);
}