Hibernate与暂态实体和分离实体有何不同?

编程入门 行业动态 更新时间:2024-10-26 20:35:03
本文介绍了Hibernate与暂态实体和分离实体有何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

文档引用:

已分离

该实体具有关联的标识符,但不再关联 具有持久性上下文(通常是因为持久性上下文 已关闭或实例已从上下文中撤出)

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与暂态实体和分离实体有何不同?

本文发布于:2023-11-22 08:36:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616716.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实体   有何不同   Hibernate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!