【发布时间】:2017-05-24 14:02:12
【问题描述】:
Exception:
failed to lazily initialize a collection of role: com.cerner.budgetmanagement.model.Team.users, could not initialize proxy - no Session (through reference chain: com.cerner.budgetmanagement.model.Team["users"])
有人能解释一下为什么会这样吗?我学习在春季/休眠环境中使用球衣。我对这种延迟初始化的理解是因为会话超出了范围。提前致谢。
@SuppressWarnings({ "unchecked"})
@GET
@Path("/name/{teamId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getBudgetPlan(@PathParam("teamId") int teamId) {
teamDao = applicationContext.getBean("dao", Dao.class);
final Team team = teamDao.getModelById(Team.class, teamId);
Hibernate.initialize(team);
return Response.status(201).entity(team).build();
}
【问题讨论】:
标签: java spring hibernate session proxy