如何管理JPA的多重继承
大家好,我有一个问题要在JPA上使用四个多inhentaded桌子进行操作。 我有四个entites
@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 table,然后试图从优惠中删除客户。 现在如何配置这些类别会出现任何错误,但是如果我尝试删除客户的相关PriceIndex和Volriskoff,则所有相同的报价都相关,并且客户在PriceIndex和Volriskoff中均为。 所以我的问题是如何管理课程以使所有操作都起作用而没有任何冲突?
Hello everyone i have a problem to perform operations in jpa with four multi-inhentaded tables.
I have four entites
@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
}
this
@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
}
this
@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
}
and this
@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
}
all of them worked right untill i added vol_risk_off table and i tried to delete customers from the offer.
how the classes are now configuered doent gave any error, but if i try to delete customer a its related priceIndex and volRiskOff all related at the same offer and the customer is in both priceIndex and volRiskOff.
So my question is how can manage classes to make all operation works without anyt conflict?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论