Got it. The error happens if I call EntityManager.detach() for a previously removed entity, and the call flush().