ok, googled this forum but didn't found a final answer... maybe someone can help.
what's the recommended way to set a mapkey from a nested entity property?
We have 3 domain objects.
- Facility
- FacilityEntry
- Property - primary key is the attribute propertyId (a long value)
A Facility has several FacilityEntries:
Code:
@OneToMany(mappedBy = "facility", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@org.hibernate.annotations.MapKey(columns = { @Column(name = "propertyId") })
public Map<Property, FacilityEntry> getFacilityEntries() {
return facilityEntries;
}
Each FacilityEntry object has one Property object.
I would like to set the primary key of the property object (a long) as MapKey.
How can I archive this?
Is it the recommended way to use @org.hibernate.annotations.MapKey as shown above or do you recommend to use a @Formula (and hence create a new dummy property) in the FacilityEntry class and map that property?