Implement your primary key as a Record using an IdClass
There are various reasons to implement your own primary key representation. Your primary key may consist of multiple attributes. Or you’re following domain-driven design principles and want to use a custom type to add semantic meaning to it. Implementing a record and mapping it as an IdClass seems evident in these situations. A record is efficient, easy to implement, immutable…