我遇到了以下问题。当我尝试删除我的实体时,它会自动尝试删除外键对象。
这是我的实体:
@Entity
public class ScmoKomponente implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Size(min = 1, max = 50, message = "{standard}")
private String name;
@Temporal(javax.persistence.TemporalType.DATE)
private Date datum;
@ManyToOne(cascade = CascadeType.ALL)
private ScmoProjekt projekt;
@ManyToOne(cascade = CascadeType.ALL)
private SupplierUser lieferant;
public SupplierUser getLieferant() {
return lieferant;
}
public void setLieferant(SupplierUser lieferant) {
this.lieferant = lieferant;
}
public ScmoProjekt getProjekt() {
return projekt;
}
public void setProjekt(ScmoProjekt projekt) {
this.projekt = projekt;
}
public Date getDatum() {
return datum;
}
public void setDatum(Date datum) {
this.datum = datum;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof ScmoKomponente)) {
return false;
}
ScmoKomponente other = (ScmoKomponente) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "scmo.model.project.ScmoKomponente[ id=" + id + " ]";
}
}
删除功能:
public void deleteScmoKomponente(ScmoKomponente ScmoKomponente) {
em.remove(em.merge(ScmoKomponente));
}
和电话:
public String deleteScmoKompo() {
ss.deleteScmoKomponente(selectedKompo);
selectedKompo = null;
return scmoEditKompo();
}
当我现在尝试删除 scmoKomponent 时,它会自动删除数据库中的 ScmoProjekt 和 SupplierUser 对象。