我正在开发一个spring mvc,我有一个旅行停止模型和一个物品交易模型。以下是我的旅程停止模式:
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Table(name="TripStop")
public class TripStopModel {
@Id
@Column(name="tripstopid")
@GeneratedValue
private Integer tripStopId;
@OneToMany(mappedBy = "tripStopModel", cascade = CascadeType.REMOVE)
private List<ItemTransactionModel> itemTransactionModelList;
}
以下是我的商品交易模型:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name="itemTx")
public class ItemTransactionModel {
@Id
@Column(name="itemTxid")
@GeneratedValue
private Integer itemTxId;
@Column(name="itemcode")
private String itemCode;
@Column(name="weight")
private String weight;
@Column(name="bagcount")
private Integer bagCount;
@ManyToOne(optional=true)
@JoinColumn(name="tripstopid")
private TripStopModel tripStopModel;
}
itemtx表是tripstop的子表。我希望无论何时从tripstop表中删除记录,其itemtx表中的子记录都应自动删除。这就是我使用级联类型删除的原因。但它没有用。以下是删除行程停止模型代码:
Session session = sessionFactory.getCurrentSession();
session.delete(tripStopModel);