A characterization of rational singularities