Java Hibernate ConstraintViolationException:无法删除子对象的SortedSet集合
我有以下两类:Java Hibernate ConstraintViolationException:无法删除子对象的SortedSet集合,java,hibernate,treeset,Java,Hibernate,Treeset,我有以下两类:索赔(父类)和索赔(子类)。详情如下: public class Claim { private SortedSet<ClaimInsurance> claimInsurances = new TreeSet<ClaimInsurance>(); @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="claim", orphanRemoval=true)
索赔
(父类)和索赔
(子类)。详情如下:
public class Claim {
private SortedSet<ClaimInsurance> claimInsurances = new TreeSet<ClaimInsurance>();
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="claim", orphanRemoval=true)
@Sort(type=SortType.NATURAL)
public SortedSet<ClaimInsurance> getClaimInsurances() {
return this.claimInsurances;
}
public void setClaimInsurances(SortedSet<ClaimInsurance> claimInsurances) {
this.claimInsurances = claimInsurances;
}
}
当我按如下方式更改索赔
类中的索赔
映射时,一切正常:
private Set<ClaimInsurance> claimInsurances = new HashSet<ClaimInsurance>();
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="claim", orphanRemoval=true)
public Set<ClaimInsurance> getClaimInsurances() {
return this.claimInsurances;
}
public void setClaimInsurances(Set<ClaimInsurance> claimInsurances) {
this.claimInsurances = claimInsurances;
}
private Set claimInsurances=new HashSet();
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy=“claim”,orphanRemoving=true)
公共集getClaimInsurances(){
返回此。索赔保险;
}
公共无效setClaimInsurances(setClaimInsurances){
this.claimInsurances=claimInsurances;
}
问题似乎是当我在映射中使用Set
(HashSet
)时,它会起作用,但是如果我改为使用SortedSet
(TreeSet
),它会给出一个错误
实际的问题是什么?我错过了什么?好的。现在问题解决了。借助@JB Nizet 对于相同的
索赔
我有几个索赔
,它们的compareTo()
给出了相同的结果
我将
claimissure
中的compareTo()更改为,这样它将为同一索赔返回不同的值。就是这样,它现在可以工作了。好的。现在问题解决了。借助@JB Nizet
对于相同的索赔
我有几个索赔
,它们的compareTo()
给出了相同的结果
我更改了ClaimInsurance
中的compareTo()
,这样它将为同一索赔返回不同的值。就是这样,它现在可以工作了。您的compareTo()
方法是如何实现的?公共int compareTo(ClaimInsurance other){返回这个.getInsuranceOrderCodeMaster().compareTo(other.getInsuranceOrderCodeMaster());
这是InsuranceOrderCodeMaster的compareTo()…public int compareTo(InsuranceOrderCodeMaster other){Integer this_id=Integer.valueOf(this.getInsuranceOrderCodeId());Integer other_id=Integer.valueOf(other.getInsuranceOrderCodeId());返回此_id.compareTo(other_id);}
对于同一索赔,您是否可以使用同一保险代码母版获得多个索赔保险?否。对于相同的索赔
在黑暗中拍摄的每个索赔
,都有唯一的保险代码,但是equals()和hashCode()方法是否与compareTo()一致?是否已打开SQL日志记录以查找Hibernate尝试删除的行以及删除的顺序?如何实现compareTo()
方法?public int compareTo(ClaimInsurance other){返回this.getInsuranceOrderCodeMaster().compareTo(other.getInsuranceOrderCodeMaster())
这是InsuranceOrderCodeMaster的compareTo()…..public int compareTo(InsuranceOrderCodeMaster other){Integer this_id=Integer.valueOf(this.getInsuranceOrderCodeId());Integer other_id=Integer.valueOf(other.getInsuranceOrderCodeId());返回此_id.compareTo(other_id)}
对于同一索赔,您可以使用同一保险代码母版拥有多个索赔吗?否。对于同一索赔的每个索赔
都有唯一的保险代码,但是equals()和hashCode()方法是否与compareTo()一致?是否已打开SQL日志以查找Hibernate尝试删除的行以及删除顺序?
org.hibernate.exception.ConstraintViolationException: could not delete: [com.omnimd.pms.beans.Claim#201]
...
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The DELETE statement conflicted with the REFERENCE constraint "FK_RCMSClaimInsuranceTable_RCMSClaimTable". The conflict occurred in database "Omnimdv12", table "dbo.RCMSClaimInsuranceTable", column 'ClaimId'.
private Set<ClaimInsurance> claimInsurances = new HashSet<ClaimInsurance>();
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="claim", orphanRemoval=true)
public Set<ClaimInsurance> getClaimInsurances() {
return this.claimInsurances;
}
public void setClaimInsurances(Set<ClaimInsurance> claimInsurances) {
this.claimInsurances = claimInsurances;
}