Spring MVC:无法初始化代理-没有会话(通过参考链) [英] Spring MVC :could not initialize proxy - no Session (through reference chain)
问题描述
类型异常报告
消息无法写入内容:无法延迟初始化角色集合: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屋!