hibernate一对多关系映射报错: could not initialize proxy - no Session

terrence_tian 发布于 2013/07/22 17:45
阅读 1K+
收藏 0

当查询一的这边时,出现错误:could not initialize proxy - no Session。 我的操作是在一个事务里面,使用spring来管理事务,所以session应该不会提前关闭呀???

 应该不是事务的问题呀!我只要不操作子表的数据,那父表的数据是可以正常显示出来的,我考虑可能是懒加载的问题,然后去配置@OneToMany(fetch=FetchType.EAGER),可是还是不行。然后报了另外一个错误:HTTP Status 500 - Handler processing failed; nested exception is java.lang.StackOverflowError  

一的这边配置

@Cascade(CascadeType.ALL)

@OneToMany

@JoinColumn(name="goodsUuid")

private Set<ReptileModel> reptileList = new HashSet<ReptileModel>();

 

多的这边配置

@ManyToOne

@JoinColumn(name="goodsUuid")

private GoodsModel goodsModel;

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.xiaoxing.shangjia.goods.vo.GoodsModel.reptileList, could not initialize proxy - no Session
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)


加载中
0
华灯初上风满楼
华灯初上风满楼

不知道这样配置行不行:

多方配置:
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "goodsUuid")

一方配置:
  @OneToMany(targetEntity = ReptileModel.class, cascade = { CascadeType.ALL }, mappedBy = "goodsModel")
  @Fetch(FetchMode.SUBSELECT)

返回顶部
顶部