This is too little code to really say, the DAO itself is not enough, people normally needs some more context, but I suspect that the fact that you are ignoring the return value of merge might be causing your problems. The following scenario: DomainObject do = new DomainObject(); // new state dao.save(do); // here, the thing gets merged, which means a new instance is created and put in the persistence context and returned, and you ignore the returned result; unfortunately, do remains in new state, and it's the returned (and ignored) value that ist detached
do.setFoo(17); dao.update(do); // here, you are not dealing with a detached instance, but again, a new one Try to change the code so that the return value of merge does get used. Again, this is just a suspicion. wujek On Wed, Nov 21, 2012 at 7:50 PM, transmeta01 <[email protected]> wrote: > 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. > -- You received this message because you are subscribed to the Google Groups "google-guice" group. 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.
