Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC :could not initialize proxy - no Session (through reference chain)

Tags:

json

spring

type Exception report

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.

like image 682
Anand Godar Avatar asked Dec 09 '22 01:12

Anand Godar


1 Answers

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;
like image 153
Anand Godar Avatar answered Dec 11 '22 07:12

Anand Godar