[ACCEPTED]-How to implement update () method in DAO using EntityManager (JPA)?-entitymanager
Accepted answer
According to the JPA specifications, EntityManager#merge()
will 6 return a reference to another object than the one 5 passed in when the object was already loaded 4 in the current context. So, I'd rather return 3 the result of the merge()
and write the update()
method 2 like this:
@PersistenceContext
private EntityManager em;
public User update (User transientUser) {
return em.merge(transientUser);
}
Then, use it like this (skipping 1 the initialization part):
user.setPhone("YYYYYY");
user = dao.update(user);
change the property and then use EntityManager 1 merge()
http://java.sun.com/javaee/5/docs/api/javax/persistence/EntityManager.html#merge%28T%29
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.