Spring MVC:无法初始化代理-没有会话(通过参考链) [英] Spring MVC :could not initialize proxy - no Session (through reference chain)

查看:145
本文介绍了Spring MVC:无法初始化代理-没有会话(通过参考链)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类型异常报告

消息无法写入内容:无法延迟初始化角色集合:edu.waa.classified.dto.User.products,无法初始化代理-没有会话(通过参考链:java.util.ArrayList [0] -> edu.waa.classified.dto.User ["products"]);嵌套异常是com.fasterxml.jackson.databind.JsonMappingException:无法延迟初始化角色集合:edu.waa.classified.dto.User.products,无法初始化代理-没有会话(通过参考链:java.util. ArrayList [0]-> edu.waa.classified.dto.User ["products"])

message Could not write content: failed to lazily initialize a collection of role: edu.waa.classified.dto.User.products, could not initialize proxy - no Session (through reference chain: java.util.ArrayList[0]->edu.waa.classified.dto.User["products"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize a collection of role: edu.waa.classified.dto.User.products, could not initialize proxy - no Session (through reference chain: java.util.ArrayList[0]->edu.waa.classified.dto.User["products"])

说明服务器遇到内部错误,导致服务器无法满足此请求.

description The server encountered an internal error that prevented it from fulfilling this request.

推荐答案

我刚刚在@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)注释的后面添加了@JsonIgnore.

I just added the @JsonIgnore at the after the @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) annotations.

它起作用了,但是不确定为什么起作用.

It worked, but not sure why it worked.

@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name = "WISHLIST", joinColumns = {
@JoinColumn(name = "userId", referencedColumnName = "id") }, inverseJoinColumns = {
@JoinColumn(name = "productId", referencedColumnName = "id") })
@JsonIgnore
private List<Product> products;

这篇关于Spring MVC:无法初始化代理-没有会话(通过参考链)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆