Hey all,
Here is the base of the conversation:
A table has a primary key. This primary key could be a composite key, and could be a composite key that there is no associated technical key.
An entity/pojo also should/need to have a way for it to be uniquely identified. In JPA spec, that is with the @Id annotation.
So -- what happens when you have many-to-many mapping tables exposed, or mini-FACT tables that are multiple many-to-many mappings and therefore large composite keys?
Let's take for example a security table where a user does work on behalf of other people based on specific roles:
USER_ID
BEHALF_ID
ROLE_ID
triple-key composite entity/pojo (let's assume you are not going to always work with associations).
Since the only fields for this entity/pojo are those three fields, by convention you create an SecurityId class that is embedded as the ID of the entity/dto....but that's the only thing in it!
Is there a practice to have the three fields just directly visible in the entity/dto, but have a 'calculated' field (like the hashCode) be the @Id annotation even though it would be transient when trying to save back to the database?
|