已删除的实体传递给持久异常 [英] Deleted entity passed to persist exception

查看:75
本文介绍了已删除的实体传递给持久异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的实体:


Document
| n ..

..1 |
DocumentType
| 1 ..

.. n |
PropertyType
| 1 ..

.. n |
DocumentProperty

我只是尝试删除一个文件,例如:
entityManager.remove(document);
p>

但错误正在解雇:


16:45:51,499错误[[Seam资源Servlet]] Servlet.service()用于servlet Seam Resource Servlet抛出异常
javax.persistence.EntityNotFoundException:已删除的实体传递给persist:[up.docstore.PropertyType#]


< blockquote>

问题似乎来自这里:

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

如果我删除了CascadeType.PERSIST,它就可以工作了。
但是我需要它,也需要它EAGERLY。

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

编辑:删除了DELETE_ORPHAN cascade,但仍然存在相同的问题。 解决方案

b
$ b



  • @ManyToOne关系中有一个CascadeType.REMOVE!删除它。


为什么选择此解决方案?



  • 如果您想要删除您不想删除其父母的孩子,因为可能有其他孩子与其父母相关。



I have this kind of entities:

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

I simply try to remove a document like: entityManager.remove(document);

but an error is firing:

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#]

The problem seems to come from here:

@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>();

If i remove CascadeType.PERSIST all it's working. But i need it there and also i need it EAGERLY.

Does anyone know other solution?

Edit: removed DELETE_ORPHAN cascade, but still the same problem.

解决方案

Solution:

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

Why this solution?

  • 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.

这篇关于已删除的实体传递给持久异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆