我是新来的冬眠。我需要在带有注释的休眠中引入删除功能。即,一旦我们删除了父记录,它需要删除子记录,即我需要引入 ondelete 级联功能。你能帮忙介绍一下这个功能吗?请在下面找到是 java/entity 代码。
@Entity
@Table(name = "atfLabel", uniqueConstraints = @UniqueConstraint(columnNames = {"key_", "module_id"}))
@SuppressWarnings("serial")
public class Label {
private long id;
private ModuleImpl module;
private String key;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@ManyToOne(optional=false)
@JoinColumn(name="module_id", nullable=false, updatable=false)
public ModuleImpl getModule() {
return module;
}
public void setModule(ModuleImpl module) {
this.module = module;
}
@Column(name="key_", length=160)
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
}
@Entity
@Table(name = "atfModule")
@SuppressWarnings("serial")
public class ModuleImpl implements Module {
private long id;
private String name;
private String description;
@OneToMany(mappedBy="module")
@Cascade(CascadeType.DELETE)
private List<Label> label;
@Override
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Override
@Column(length=200, unique=true, nullable=false)
public String getName() {
return name;
}
@Override
@Column(length=2000)
public String getDescription() {
return description;
}
@Override
public void setName(String name) {
this.name=name;
}
@Override
public void setDescription(String desc) {
this.description=desc;
}
}
@Entity
@Table(name = "atfLabelText",
uniqueConstraints = @UniqueConstraint(columnNames = { "label_id", "tenant_id", "locale" }))
@SuppressWarnings("serial")
public class LabelText {
private long id;
private Label label;
private TenantImpl tenant;
private String locale;
private String text;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public long getId() {
return id;
}
@ManyToOne(optional = false)
@JoinColumn(name = "label_id", nullable = false, updatable = false)
public Label getLabel() {
return label;
}
public String getLocale() {
return locale;
}
@ManyToOne(optional = true, fetch = FetchType.LAZY)
@JoinColumn(name = "tenant_id", nullable = true, updatable = false)
public TenantImpl getTenant() {
return tenant;
}
@Column(length = 1500)
public String getText() {
return text;
}
public void setId(long id) {
this.id = id;
}
public void setLabel(Label label) {
this.label = label;
}
public void setLocale(String locale) {
this.locale = locale;
}
public void setTenant(TenantImpl tenant) {
this.tenant = tenant;
}
public void setText(String text) {
this.text = text;
}
}
你能帮我如何做删除功能和ondelete级联未来。谢谢维贾亚库马尔