Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Questions about Spring @Transactional annotation and EM's

I'm no Spring expert, but assuming it behaves the same way as SessionBeans,
each transaction will have a new EntityManager.  So inside your delete, you
will need to re-find the object by its id then delete it.

tch wrote:
> 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 :)
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx

--- James Sutherland
 EclipseLink ,
Wiki: EclipseLink , TopLink 
Forums: TopLink , EclipseLink 
Book: Java Persistence 
View this message in context:
Sent from the EclipseLink - Users mailing list archive at

Back to the top