I have some entities that are in many-to-many, bidirectional relationships with very large numbers of other entities (millions). Deleting one of them the naive way (walking through all the related entities and remove()-ing it from their collections) is not feasible, so I used a native SQL query to remove all references from the join table. This almost works fine. Unfortunately, some small number of those millions of related entities are usually being managed, but I don't know which ones. If I knew which they were, I could call refresh() on each.
Is there some way of finding out which entities of a given type are currently being managed? Is there some better way of accomplishing this delete?