gpt4 book ai didi

java - 已删除的实体传递给持久异常

转载 作者:搜寻专家 更新时间:2023-10-30 21:47:18 24 4
gpt4 key购买 nike

我有这种实体:

Document | n .. to ..1 | DocumentType | 1 .. to .. n | PropertyType | 1 .. to .. n | DocumentProperty

我只是尝试删除如下文档:entityManager.remove(文档);

但是一个错误正在触发:

16:45:51,499 ERROR [[Seam Resource Servlet]] Servlet.service() for servlet Seam Resource Servlet threw exception javax.persistence.EntityNotFoundException: deleted entity passed to persist: [up.docstore.PropertyType#]

问题似乎出自这里:

@OneToMany(mappedBy = "documentType", cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
@ForeignKey(name = "FK_DOCUMENT_TYPE__PROPERTY_TYPE")
@Sort(type = SortType.NATURAL)
private SortedSet<PropertyType> propertyTypes = new TreeSet<PropertyType>();

如果我删除 CascadeType.PERSIST 所有它的工作。但我在那里需要它,而且我非常需要它。

有人知道其他解决方案吗?

修改:删除了DELETE_ORPHAN级联,但还是一样的问题。

最佳答案

解决方案:

  • There was a CascadeType.REMOVE in a @ManyToOne relationship ! Removed it.

为什么是这个解决方案?

  • if you want to delete a child you SURELY do not want to delete its parent because there can be other children related to that parent.

关于java - 已删除的实体传递给持久异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2178304/

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