False positives for transient-checks for deleted entities

The new transient-checks for deleted entities introduced with 6.6.0 are pretty useful because they surfaces implementation glitches. However, it raises false errors when entities are remove with a bulk deletion. For example, deleting entities with

em.createQuery("DELETE FROM Deployment d WHERE d.m_scope =: scopeId")
    .setParameter(":scopeId", scopeId)
    .executeUpdate();

will raise a wrong TransientObjectException later on that claims that one of the deleted Deployments is referencing another deleted (and hence transient) entity. However, using

em.createQuery("SELECT d FROM Deployment d WHERE d.m_scope = :scopeId")
    .setParameter(":scopeId", scopeId)
    .getResultStream()
    .forEach(em::remove);

i.e. an explicit remove works as expected without raising an exception.

The thing is, you have to detach objects from the session before you run the bulk deletion queries and remove all references to the objects that are about to be deleted from entities within the session. Also see the word of caution in the specification.