Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
529 views
in Technique[技术] by (71.8m points)

spring data jpa - EmbeddedId not in sync with relationship

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...