我有这样的实体:
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.