I have the below data structure, I have a doubt regarding having the embedded id in sync with mapped data.
@Data
@Builder
public class Product{
@Embedded
private ProductId productId;
@ManyToOne(fetch = FetchType.EAGER)
@MapsId("locationId")
private Location location;
}
@Embeddable
public class ProductId{
@Column(name="item_id")
private Integer id;
@Column(name="location_id")
private Integer locationId;
}
How would i keep the field location
in sync with locationId
in ProductId
or vice versa.
Should I write custom setters to set values for embedded id when setting value for location
?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…