Fixed performance in Entity.flush