我有三张桌子:
1)卫生 2)UNITDATA 3)数据
数据(PK)的ID在Sanitation和UnitData表上用作FK。所以,我认为,如果我必须从Data表中删除任何数据 - 首先我必须从Sanitation和UnitData表中删除数据。这是我的控制器:
@ExternalRestrictions("Edit Data")
public static int delete(Long id) {
int confirm = 1;
if(request.isAjax()) {
List<Sanitation> sanitation1 = Sanitation.find("data_id = ?", id).fetch();
if(sanitation1.size()!=0){
Sanitation sanitation = sanitation1.get(0);
Logger.info("sanitationget: " + sanitation1.get(0));
sanitation.delete();
sanitation.refresh();
}
List<UnitData> unitData1 = UnitData.find("data_id = ?", id).fetch();
Logger.info("unidatasize: " + unitData1.size());
for(int i=0;i<unitData1.size();i++){
UnitData unitdata = unitData1.get(i);
unitdata.delete();
unitdata.refresh();
}
Data data = Data.findById(id);
Logger.info("data: "+ data);
data.delete();
data.refresh();
return confirm;
}
模型是:
1)数据模型:
public String submissionId;
public String groupTagName;
public String respondentId;
public Boolean isVisited;
public Date resolveDate;
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
public SchoolInformation schools;
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
public Ngo ngo;
public int iteration = 1;
public int approvalStatus;
public int approvalState;
otherwise true */
public Boolean isFarmerActive = true;
@Required
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
public Form form;
@Lob
@Basic(fetch = FetchType.LAZY)
public byte[] xml;
@Lob
@Basic(fetch = FetchType.LAZY)
public byte[] dataSpecificXml;
@Required
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
public User sender;
@Required
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
public Role senderRole;
public Boolean webEntry = false;
@Transient
public List items;
public Date received;
public Date startTime;
public Date endTime;
public String[] audioData;
public Double latitude;
public Double longitude;
public Double accuracy;
public String image;
public Boolean isExtracted = false;
public String webOrMob = "";
2)UnitData模型:
@Required
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
public Data data;
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
public Form form;
@Required
public String titleVar;
public String title;
public String type;
public String valueVar;
@Column(length=1023)
public String value;
public String extraValue;
@Required
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
public FormResource formResource;
@Min(0)
public int iterationNo;
3)卫生模式:
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
public Data data;
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
public Form form;
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
public User sender;
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
public SchoolInformation school;
public String month = "";
public String res_type = "";
public String num_toilet_unusable = "";
public String why_toilet_unusable = "";
public String toilet_clean_interval = "";
public String harpic = "";
public String is_sanitation_prob_informed = "";
public String how_informed_sanitation_prob = "";
public String how_informed_sanitation_prob_other = "";
public String took_step_sanitation_prob = "";
public String rank_sanitation = "";
当我尝试删除时(点击删除按钮),它会在 sanitation.delete()行中显示错误:
发生PersistenceException: org.hibernate.exception.ConstraintViolationException:不能 执行JDBC批量更新
问题出在哪里?