[英]How to manage multiple inheritance on jpa
大家好,我在 jpa 中使用四个多内置表执行操作时遇到问题。 我有四个实体
@Entity
@Table(name = "offer")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Offer extends AbstractAuditingEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "offer_seq")
@SequenceGenerator(name = "offer_seq", sequenceName = "offer_seq", allocationSize = 1)
private Long id;
//... other fields
@OneToMany(mappedBy = "offer", cascade = CascadeType.ALL, orphanRemoval = true)
@JsonIgnore
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Customer> customers = new HashSet<>();
@OneToMany(mappedBy = "offer", cascade = CascadeType.ALL, orphanRemoval = true)
@JsonIgnore
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<PriceIndex> prices = new HashSet<>();
@OneToMany(mappedBy = "offer", cascade = CascadeType.ALL, orphanRemoval = true)
@JsonIgnore
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<VolRiskOff> volRiskOff = new HashSet<>();
//... constructors , getters and setters
}
这个
@Entity
@Table(name = "price_index")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class PriceIndex extends AbstractAuditingEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "price_index_seq")
@SequenceGenerator(name = "price_index_seq", sequenceName = "price_index_seq",
allocationSize = 1)
private Long id;
//... other fields
@ManyToOne
private Offer offer;
@ManyToOne
private Customer customer;
//... constructors , getters and setters
}
这个
@Entity
@Table(name = "vol_risk_off")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class VolRiskOff implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "vol_risk_off_seq")
@SequenceGenerator(name = "vol_risk_off_seq", sequenceName = "vol_risk_off_seq",
allocationSize = 1)
private Long id;
//... other fields
@ManyToOne(fetch = FetchType.LAZY)
@NotFound(action = NotFoundAction.IGNORE)
@JoinColumn(name = "customer_id")
private Customer customer;
@ManyToOne
@NotFound(action = NotFoundAction.IGNORE)
@JoinColumn(name = "offer_id")
private Offer offer;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "price_index_id", referencedColumnName = "id")
private PriceIndex priceIndex;
//... constructors , getters and setters
}
和这个
@Entity
@Table(name = "customer")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Customer extends AbstractAuditingEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "customer_seq")
@SequenceGenerator(name = "customer_seq", sequenceName = "customer_seq",
allocationSize=1)
private Long id;
//... other fields
@ManyToOne
private Offer offer;
@OneToMany(mappedBy = "customer")
@JsonIgnore
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<PriceIndex> priceIndexes = new HashSet<>();
@OneToMany(mappedBy = "customer", cascade = CascadeType.REMOVE, orphanRemoval = true)
@JsonIgnore
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@NotFound(action = NotFoundAction.IGNORE)
private Set<VolRiskOff> volRiskOff = new HashSet<>();
//... constructors , getters and setters
}
在我添加 vol_risk_off 表并且我试图从报价中删除客户之前,所有这些都正常工作。 现在如何配置类并没有给出任何错误,但是如果我尝试删除客户,其相关的 priceIndex 和 volRiskOff 都与同一报价相关,并且客户同时在 priceIndex 和 volRiskOff 中。 所以我的问题是如何管理类以使所有操作都可以正常工作而不会发生冲突?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.