文档引用:
已分离
该实体具有关联的标识符,但不再关联 具有持久性上下文(通常是因为持久性上下文 已关闭或实例已从上下文中撤出)
the entity has an associated identifier, but is no longer associated with a persistence context (usually because the persistence context was closed or the instance was evicted from the context)
这是否意味着休眠状态保留对曾经持久化的所有对象的引用? 但这会导致内存舔.
Does it mean that hibernate keep references to all objects that have been ever persistence? But then it would cause memory lick.
或者这意味着实体具有与数据库中的实体相对应的ID,则将得出两个结论: 1)仅在查询数据库时可以检查. 2)如果三分之一的实体将从数据库中删除该实体,则分离的实体可能会变得短暂.
Or it means that entity has an id that corresponds to an entity in a database then it would lead to two conclusions: 1) It can be checked only querying a database. 2) A detached entity can become transient if some one third would delete the entity from the database.
推荐答案我在文档中没有找到与此相关的任何内容,但是我相信它确实可以跟踪分离的实体……例如,根据JPA规范,您拥有提取实体时的情况(但不是惰性关系)...如果分离该实体然后再次合并,它将考虑已卸载的关系,但是如果将关系设置为null,则合并后将还设置为null ...所以如果不保存分离的记录该如何区分...在层叠.MERGE行为中还有一些情况可能告诉它保存了以前分离的实体的记录.. ..再次是我所期望的,那里没有文档
I didn't find anything in the documentation regarding this, but I believe it does track detached entities ... for example, According to JPA specs, you have the case when an entity was fetched (but its lazy relations are not) ... If you detach this entity then merge it again , It considers the the relations unloaded, but if you set the relation to null, then after merging it will be also set to null ... so how will it differentiate if it doesn't keep record of the detached ... there are also some scenarios in the cascade.MERGE behavior that might tell that it keeps record of the previously detached entities .... again this is what I expect, no documentation there
更多推荐
Hibernate与暂态实体和分离实体有何不同?
发布评论