- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个问题:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: mvc3.model.Topic.comments, no session or session was closed
这是模型:
@Entity
@Table(name = "T_TOPIC")
public class Topic {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
@ManyToOne
@JoinColumn(name="USER_ID")
private User author;
@Enumerated(EnumType.STRING)
private Tag topicTag;
private String name;
private String text;
@OneToMany(mappedBy = "topic", cascade = CascadeType.ALL)
private Collection<Comment> comments = new LinkedHashSet<Comment>();
...
public Collection<Comment> getComments() {
return comments;
}
}
调用模型的 Controller 如下所示:
@Controller
@RequestMapping(value = "/topic")
public class TopicController {
@Autowired
private TopicService service;
private static final Logger logger = LoggerFactory.getLogger(TopicController.class);
@RequestMapping(value = "/details/{topicId}", method = RequestMethod.GET)
public ModelAndView details(@PathVariable(value="topicId") int id)
{
Topic topicById = service.findTopicByID(id);
Collection<Comment> commentList = topicById.getComments();
Hashtable modelData = new Hashtable();
modelData.put("topic", topicById);
modelData.put("commentList", commentList);
return new ModelAndView("/topic/details", modelData);
}
}
jsp 页面如下所示:
<%@page import="com.epam.mvc3.helpers.Utils"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
<title>View Topic</title>
</head>
<body>
<ul>
<c:forEach items="${commentList}" var="item">
<jsp:useBean id="item" type="mvc3.model.Comment"/>
<li>${item.getText()}</li>
</c:forEach>
</ul>
</body>
</html>
查看jsp时出现异常。在带有 c:forEach 循环的行
最佳答案
如果您知道每次检索主题
时都希望看到所有评论
,请更改评论
的字段映射至:
@OneToMany(fetch = FetchType.EAGER, mappedBy = "topic", cascade = CascadeType.ALL)
private Collection<Comment> comments = new LinkedHashSet<Comment>();
集合默认是延迟加载的,看看this如果您想了解更多。
关于java - 如何解决Hibernate异常 “failed to lazily initialize a collection of role”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57429223/
我正在评估在 Azure 中部署 Web 服务的各种选项。目前,Web 服务将仅由前端 UI 使用,该前端 UI 将作为单独的 Web 角色部署在托管 Web 服务的同一云服务中。然而,Web 服务将
我正在尝试在 Azure 中创建一个自定义角色,允许订阅“所有者”执行几乎所有操作,但取消/重命名自己的订阅或移至另一个管理组。 我还希望他们能够向他们想要的人授予正确的访问权限(特别是内置的“贡献者
我是 Ansible 的新手,我已经创建了我的第一个 Ansible 角色剧本,当我尝试运行它时,它抛出了下面的错误,而角色之外的其他模块(如处理程序、模板)工作正常。我仅通过剧本中的角色观察到这个问
我正在使用 Selenium 进行自动化测试。有什么区别 java -jar selenium-server-standalone-2.24.1.jar -role hub 和 java -jar s
根据WAI-ARIA specification两个角色都应该有: 关注第一个可聚焦元素 用户不能离开对话框 应该设置适当的 aria-label 应该用来中断流程,并且应该要求采取一些行动,例如单击
我想设计一个具有以下要求的数据库,但我遇到了问题。 我有 3 种类型的用户:医生、注册用户和管理员。将来我可能会添加其他类型的用户。这些用户类型中的每一种都有不同的配置文件字段。例如,注册用户应该有
我是 jQuery 和网页设计的新手,请原谅我问这个幼稚的问题。 关于latest jQuery mobile website ,他们的例子是: Page content goes here
我正在查看文档: http://pyqt.sourceforge.net/Docs/PyQt4/qtablewidgetitem.html#data 我可以将行 IDList.append(item.
我看到角色出现一些奇怪的异常,我不知道如何解释。角色名RD........ under ,我能期望它是什么?它是我在该特定服务组中的所有服务都在其上运行的底层机器吗? 最佳答案 Application
我正在尝试使用我的 GitHub 设置 CodeDeploy,但发现了一些问题。 我已使用 AWSCodeDeployRole 策略创建了服务角色,如文档中所述。 在我的 Code Deploy 应用
我正在尝试创建一个 Web 服务并将其部署到 Azure 云服务 场景非常简单:通过 http 或 https 向服务发送请求并接收一些数据。 我无法从文档中判断这是否应该在 WebRole 或 Wo
我从 ASP.NET Identity 的声明授权开始,如果我的应用程序中需要“角色”概念,我想阐明处理它们的方式。 注意:我对这个真的很陌生,所以所有的概念都在我脑海中飞舞,请多多关照,对于任何概念
我知道这个问题与一些类似,但我的设置与那些不同。 EF 中具有以下类的正确配置是什么? 这里的问题是 Team有一个可选的 DivisionParticipant ,但是 DivisionPartic
我无法运行 Windows Azure Hello World 示例。它给了我以下错误: “一个或多个角色启动角色失败”。 我将项目放在 D 驱动器的根目录中,以确保路径长度不是问题。我还清除了 Az
我正在尝试向我的 Xcode 添加一个帐户,但我一直收到此错误。另一个 Xcode 上的相同帐户可以完美运行。我有其他帐户运行良好。 错误是(如标题所述) The role information i
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
在 Bash 脚本中,我想删除 Postgres 用户角色。但是 Postgres 不允许我这样做,我得到了 Cannot drop table X because other objects dep
我目前正在设置一个新项目并创建我的登录系统。由于某种原因,它似乎正在搜索角色表?到目前为止,这是我的结构: Controller public function action_index() {
我有三个模型,一个用户,一个个人资料和一个角色,我试图通过个人资料角色附加到用户强>. # user.rb class User :profiles has_many :users end 我正
我想使用 Spring Security JSP 标签库根据角色有条件地显示一些内容。但是在 Spring Security 3.1.x 中只检查一个角色。 我可以使用,但 ifAllGranted
我是一名优秀的程序员,十分优秀!