gpt4 book ai didi

java - 如何删除孤立记录?

转载 作者:太空宇宙 更新时间:2023-11-04 07:19:51 26 4
gpt4 key购买 nike

我正在使用 CascadeType.ALL,但是当我尝试删除记录时,它只是删除该记录而不是其关联的记录。

@OneToMany(cascade = CascadeType.ALL)
@LazyCollection(LazyCollectionOption.FALSE)
public List<CartItem> getItems() {
return items;
}

我的 table 是

cart
cartitem
cart_cartitem

当我使用以下内容时,它只是删除 cart_cartitem 的记录,而不是 cartitem 的记录。

cart.getItems().remove(0);
session.update(cart);

最佳答案

你实现了equals and hashcode吗?正确吗?我还相信你正在努力消除孤儿。

@OneToMany(mappedBy = "cart", 
cascade={javax.persistence.CascadeType.ALL}, orphanRemoval = true)
private List<CartItem> getItems();

关于java - 如何删除孤立记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19483813/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com