I have DAO methods annotated with @Transactional as such:
public abstract class GenericDAO<T> implements DAO<T> {
private Class<T> persistentClass;
@PersistenceContext
EntityManager em;
public GenericDAO(EntityManager em, Class<T> persistentClass) {
this.persistentClass = persistentClass;
this.em = em;
}
public GenericDAO(Class<T> persistentClass) {
this.persistentClass = persistentClass;
}
@Transactional
@Override
public T persist(T t) {
em.persist(t);
return t;
}
@Transactional
@Override
public void delete(T t) {
em.remove(t);
em.flush();
}
@Transactional
@Override
public T update(T t) {
em.merge(t);
return t;
}
@Transactional()
@Override
public T merge(T t) {
em.merge(t);
return t;
}
@Override
public T findById(Long id) {
return em.find(persistentClass, id);
}
}
When I call merge, the DAO does an insert (new row), instead of doing an
update. What is there a specific scope the persistence context must be in
order to the update to be done? BTW, I have tried with adding em.flush()
after the call to em.merge(), but did not solve the problem.
Thank
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-guice/-/bGD8mY4-G-0J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.