> > Well, how would an entityManager know if an Entity was deleted? Would
> you expect
> > it to keep a history of all deleted Entities?
> I expect it keep track of all entities deleted within the transaction
> prior to the transaction being committed.
This is actually done in the em and this is exactly what contains() will do
AFAIK. But again, what shall it be good for? You will only see your own
change, and your code already knows what it did. You might not see what
others did on the database, possibly not using JPA at all.
> I already know the entity exists in db. What I need to know is whether
> the active transaction has removed it or not so I can decide whther to
> do a em.insert() or em.merge() operation. At present I do an em.merge()
> and if I get an exception I try em.insert. This is klunky at best.
Try em.contains().