A characterization of Hilbert spaces