persistence@glassfish.java.net

RE: Determining if entity has been removed

From: Markus KARG <markus.karg_at_gmx.net>
Date: Tue, 9 Dec 2008 18:02:14 +0100

> Well, how would an entityManager know if an Entity was deleted? Would
> you expect
> it to keep a history of all deleted Entities?
>
> To determine whether an Entity already exists you may use contains().
> One way to
> determine if a row with a certain id already exists is to use the find
> method
> with the given id. Note that this may lead to a database round trip.

Well, contains() just checks whether the entity instance is found in the
cache and was not detached. Maybe it would be better if he uses find() to
check wehter the entity instance is found in the backend store?