gpt4 book ai didi

java - JDO makeTransient 的 Hibernate 等价物是什么

转载 作者:行者123 更新时间:2023-12-02 00:46:36 26 4
gpt4 key购买 nike

我正在将 Dao 层从 KodoJDO 移植到 Hibernate。我将菜单保存在数据库中,并根据用户的权利修剪本地副本以仅显示允许用户执行的操作。

当我在 KodoJDO 中执行此操作时,我必须将正在修剪的对象设为 transient ,因为我不想将更改写回数据库。

我在 Hibernate 中没有看到任何等效的函数。有吗?如何防止这些更改写回数据库。

这是剪枝函数。

 public void prune(Collection<Entitlement> ents)
{
Session session=PersistenceManager.getManager();
// Rewrite----------------------------------
//session.makeTransient(this);

for (Iterator<Leaf> iter = leafs.iterator(); iter.hasNext();)
{
Leaf l = (Leaf) iter.next();
if(!l.isAllowed(ents))
{
iter.remove();
}
}
for (Iterator<Branch> iter = branches.iterator(); iter.hasNext();)
{
Branch b = (Branch) iter.next();
if(b!= this)
{
b.prune(ents);
}
if (b.hasNoChildren())
{
iter.remove();
}
}
}

对答案发表评论。我接受了最完整的答案,但 skaffman 和 Affe 的答案也很有值(value)。

最佳答案

evict(Object object) 是您要查找的 Session 接口(interface)上的方法。

另请注意,hibernate 中的词汇略有不同。根据 session javadoc:

transient: never persistent, not associated with any Session
persistent: associated with a unique Session
detached: previously persistent, not associated with any Session

所以 transient 并不意味着完全相同的事情。他们用“分离”这个词来形容你所说的事情。

关于java - JDO makeTransient 的 Hibernate 等价物是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4821554/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com