<p>There is provided magnetic encoder (26) of high reliability that has magnet part (27) comprising a magnetic body and a resin, exhibiting high magnetic performance so as to be capable of high-precision detection of rotational frequency; and provided relevant hub unit bearing (2a). The resin is preferably a thermoplastic resin, and still preferably comprises a thermoplastic resin having a soft segment in its molecule. The magnetic encoder (26) is further fitted with fixing member (25) of magnetic material with which the magnet part (27) is mounted. The magnet part (27) and the fixing member (25) are bonded together by means of an adhesive containing at least one of a phenolic resin and an epoxy resin.</p>