Is there a way to query the JPA EntityManager whether a given entity is detached? This SO post is discussing a similar issue but does not indicate a way to quer
To check if the given entity is managed by the current PersistenceContext you can use the EntityManager#contains(Object entity).
PersistenceContext