First flush, then get the new id before commiting the transaction or we
cannot return the new id.