Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate ConstraintViolationException:无法删除子对象的SortedSet集合_Java_Hibernate_Treeset - Fatal编程技术网

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;
}