[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] Questions about Spring @Transactional annotation and EM's
|
Ok,
So I've finally gotten a few free seconds to start looking at Spring
and JPA/EclipseLink again, and have started to run into some curious
things.
In this example I have a DAO that has 2 methods and an EM injected like this:
@PersistenceContext
private EntityManager entityManager;
@Transactional(readOnly=true)
find(..)
@Transactional(propagation = Propagation.REQUIRED)
delete(Object entity)
So in my controller I inject the dao, then do something like this:
Entity e = dao.find(..)
dao.delete(e);
EclipseLink cries and says it can't delete an unmanaged entity :/
So apparently I'm confused about what exactly is happening when I use
this @Transactional annotation. Admittedly I didn't read the docs too
thoroughly, so I'm not surprised. My options are to do the find/delete
in one @Transactional method or call a merge inside my dao's delete
method. But I don't understand why I'm getting a (different?) em even
though I'm using the same dao, in the same request. Does
@Transactional do something funky with the em? Does it not guarantee
the same one?
Thanks and don't be afraid to reply with RTFM :)