Fingerprints of the hierarchical building-up of the structure on the mass-metallicity relation