add rule for flush EntityManager before clear it

clear the EntityManager will lose all the previous operations to
EntityManager, so we need to synchronize it to RDB before we clear
it.