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

前端之家收集整理的这篇文章主要介绍了java – 删除的实体传递给持久异常前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这样的实体:

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所有它的工作.
但我需要它在那里,我也需要它EAGERLY.

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

编辑:删除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.
原文链接:https://www.f2er.com/java/125100.html

猜你在找的Java相关文章