A magnet portion 27 of a magnetic encoder 26 includes a magnetic member
and a resin, and a highly reliable magnetic encoder 26 having a high
magnetic property and enabling to detect a rotational number with high
accuracy, and a hub unit bearing 2a are provided. Further, the resin is
preferably a thermoplastic resin and further preferably includes a
thermoplastic resin including a soft segment in a molecule. Further, the
magnetic encoder 26 further includes a fixed member 25 attached with the
magnet portion 27 and comprising a magnetic material, and the magnet
portion 27 and the fixed member 25 are bonded by an adhering agent
including at least one of a phenolic resin based and an epoxy resin
based.