【发布时间】:2011-02-04 02:57:29
【问题描述】:
我正在关注一个休眠教程,其中我的数据库在“人员”和“事件”之间存在关系
两者之间存在多对多的关系。每个 Person 在 Person.class 中都有一组事件,我可以使用 personinstance.getEvents() 以编程方式访问它们
这是我想要的工作:
控制器(摘录):
List<Person> persons = personManager.getPersons();
Map<String, Object> myModel = new HashMap<String, Object>();
myModel.put("persons", persons);
return new ModelAndView("WEB-INF/jsp/hello.jsp","model",myModel);
jsp页面:
<%@ include file="include.jsp"%>
<html>
<head>
<title>Hello</title>
</head>
<body>
<h1>Persons</h1>
<br />
<c:forEach items="${model.persons}" var="person">
<c:out value="${person.firstname }" />
<c:out value="${person.lastname }" />
<c:forEach items="${person.events }" var="event">
<c:out value="${event.title }" />
</c:forEach>
<br />
</c:forEach>
</html>
错误:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: domain.Person.events, no session or session was closed
我不确定我是否以正确的方式进行此操作(使用 jstl 为每个循环嵌套),或者我是否可以通过控制器或其他方式实现我正在寻找的结果。但我需要一些建议
【问题讨论】:
标签: hibernate jsp spring-mvc jstl