- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
给定网络应用程序中的以下情况:
// EntityManager em, one per Request with Spring's OpenEntityManagerInViewFilter
// Parent oldParent, from previous request (and therefore another persistence context)
Parent parent = em.find(Parent.class, oldParent.getId());
List<Child> children = parent.getChildren(); // Mapped collection with LazyLoading
for (Child child : children) {
...
列表迭代器的调用导致 LazyInitializationException
。这很令人困惑,因为子列表的获取发生在相同的持久性上下文中(或者我错了吗?)。但是,使用merge()
,它可以工作。就好像两个请求共享一个持久化上下文。
Parent parent = em.merge(oldParent);
List<Child> children = parent.getChildren();
for (Child child : children) {
...
// No Exception!!
我的推理错误是什么?
添加
我已经证明错误不是由 parent.getId()
引起的。这是堆栈跟踪的一部分:
at org.hibernate.collection.PersistentList.iterator(PersistentList.java:138)
这意味着实际上是迭代器导致了问题。它变得更加奇怪 - 我已经检查过在第一种情况下(使用 find()
),hibernate 发出了一个 select 语句来从数据库中检索一个新对象,而不是从缓存中持久性上下文。
加法2
这里有更多的堆栈跟踪信息:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: edeka.sw.phb.model.Chapter.subChapters, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:380)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:372)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:365)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
at org.hibernate.collection.PersistentList.iterator(PersistentList.java:138)
at java.util.Collections$UnmodifiableCollection$1.<init>(Collections.java:1022)
at java.util.Collections$UnmodifiableCollection.iterator(Collections.java:1021)
//... followed by the line of the foreach.
最佳答案
我认为您的问题不在迭代部分,因为您使用最近加载的新父项进行迭代。问题必须出在似乎未加载的 .getId() 上,然后合并才起作用,因为不调用 .getId()
关于java - 为什么 EntityManager.merge() 会阻止 LazyInitializationException 而 EntityManager.find() 不会?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4326039/
我从一个 Mercurial 存储库开始,它有多个我试图 merge 到其中的子存储库,就好像它们一直是主存储库的一部分一样。它们从一开始就不应该是子存储库。 我整理了一个将旧历史转换为单个存储库的过
假设我有一个主线分支和一个功能分支。我已经多次将主线分支 merge 到功能分支中,但只有少数非常小的 merge 冲突。我想清理历史,以便最后只有一个 merge 。执行此操作的最佳方法是什么? 最
首先我使用heapq.merge创建了a&b的两个结果,但是在mergea&b之后,我发现a的列表是空的。 >>> a=merge([1,2],[3,4]) >>> b=merge([4,5],[6,
我和我的团队正在使用远离主轨道 (origin/dev) 的远程分支 (origin/our_feature_branch) 开发一项功能。 Gerrit用于审查等。 使用 git merge ori
这个问题在这里已经有了答案: Is there a way to merge with Strategy "ours" without producing a new commit? (1 个回答)
GitLab 无法自动 merge 请求。所有 merge 请求都会收到消息“此 merge 请求包含必须解决的 merge 冲突。您可以在命令行上手动尝试” 消息似乎不正确,我通过使用“git br
git 有没有办法在不 merge 文件的情况下 merge 两个分支?换句话说就是绘制 merge 箭头。 假设我有分支 A 和 B。我需要将分支 B merge 到 A,但不需要 B 中的所有更改
我想使用提供 git 集成的流行的开源问题跟踪器 (Redmine)。不幸的是,跟踪器中的每个项目只能与一个 git repo 相关联。在跟踪器中创建多个项目不是我理想的设置。 考虑到这一点,我尝试使
在我们的存储库中,我们遵循基于 git-flow 的工作流程。我们有一个已完成的发布(安装在生产环境中),因此发布分支已 merge 到主分支中。 B---C---D---E [release
git merge 命令有一个执行快进 merge 的选项,但这不是我想要的,因为如果它不能执行快进 merge ,它会使用普通 merge . 是否有一个 git 命令仅执行快进 merge (从跟
尝试合并 TFS2008 时出现此错误。源分支或目标分支上都没有挂起的更改。 TF14083: The item {0} has a pending merge from the current me
为了更好地理解这些操作,我想知道 github 或 gitlab 到底是如何 merge 这些请求的。当压缩、 rebase 、 merge ......时详细执行哪些 git 命令? 最佳答案 PR
为了更好地理解这些操作,我想知道 github 或 gitlab 到底是如何 merge 这些请求的。当压缩、 rebase 、 merge ......时详细执行哪些 git 命令? 最佳答案 PR
我试图将提交的一部分从默认分支(不是所有文件和其他文件的部分) merge 到一个命名分支。我试过 graft ,但它只需要整个提交,而没有给我选择的机会。这将如何完成? 例子: A---B---C-
我正在进行 merge ,此时我已准备好提交,但我在 TortoiseHg 中的提交对话框显示许多文件已修改,但是当我与 parent 进行比较时,它说所有文件都是二进制相等的。 我没有也从未有过 e
我已经尝试了以下几种变体,但我仍然遇到错误。有什么办法可以解决这个问题。 DB2 10.1(DB2 for z/OS V10) 对于以下 MERGE INTO TRGT t USING SRC s O
我的数据库模型有用户和 MAC 地址。一个用户可以有多个MAC地址,但一个MAC只能属于一个用户。如果某个用户设置了他的 MAC,并且该 MAC 已经链接到另一个用户,则现有关系将被删除,并在新所有者
假设我有一个新功能,所以我创建了一个新分支。这个分支是一个会持续很长时间的副项目,所以我最终将 master merge 回它以使其保持最新状态。这已经发生了 50 次,因为我一直在更新它并消除该功能
过去几个小时我在 Mercurial 中进行了一次巨大的 merge 。 merge 131 个文件后,我的 merge 工具 meld 崩溃,显示 python 回溯。在尝试退出 meld 时,我无
我有一个关于 git merge 的问题。假设我的存储库中有两个分支(本地和远程):master 和 test。当我在测试分支上工作时,主分支被其他人更新了。在终端中,我写: git checkout
我是一名优秀的程序员,十分优秀!