I believe you can have a couple of options.
- You can simply leave the
country primitive from your domain class completely. If you do not need it, there is no reason to tell Hibernate to get it. - If you are not going to change it at any comparison in your domain class and apply the
@Transitive annotation, you can get what you need. This tells Hibernate that nothing about the country identifier is required at the database level.
Any of these methods helps ensure referential integrity between the employee object and the country identifier. However, I would recommend using the first one. If you have no reason to ever need a country identifier, do not make it part of the object in the first place.
If you need to use the country identifier for relations on the back, I would recommend including this
@Column(name = "country", insertable = "false", updatable = "false").
This allows you to get the country identifier without fear that you overwrite it by accident.
Hope this helps!
Jason lowenthal
source share