я пытаюсь загрузить storebyid, но при удалении @ManyToMany (mappedBy = "stores") приватно показываю ошибку
Hibernate: select store0_.store_id as store_id1_6_0_, store0_.status as status2_6_0_, store0_.storename as storenam3_6_0_ from store store0_ where store0_.store_id=?
Hibernate: select products0_.store_id as store_id2_4_0_, products0_.product_id as product_1_4_0_, product1_.product_id as product_1_3_1_, product1_.price as price2_3_1_, product1_.productname as productn3_3_1_ from product_store products0_ inner join product product1_ on products0_.product_id=product1_.product_id where products0_.store_id=?
2562-07-05 16:02:01.197 WARN 15200 --- [nio-8080-exec-9] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: com.gpch.hotel.model.Store["products"])
2562-07-05 16:02:01.198 WARN 15200 --- [nio-8080-exec-9] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: com.gpch.hotel.model.Store["products"])
2562-07-05 16:02:01.198 WARN 15200 --- [nio-8080-exec-9] o.h.e.loading.internal.LoadContexts : HHH000100: Fail-safe cleanup (collections) : org.hibernate.engine.loading.internal.CollectionLoadContext@876165<rs=HikariProxyResultSet@11556352 wrapping com.mysql.jdbc.JDBC42ResultSet@1095230>
package com.gpch.hotel.model;
import lombok.Data;
import javax.persistence.*;
import java.util.List;
import java.util.Set;
@Data
@Entity
@Table(name = "store")
public class Store {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "store_id")
private int id;
@Column(name = "storename")
private String storeName;
@Column(name = "status")
private String status;
@ManyToMany(mappedBy = "stores")
private Set<Product> products;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getStoreName() {
return storeName;
}
public void setStoreName(String storeName) {
this.storeName = storeName;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Set<Product> getProducts() {
return products;
}
public void setProducts(Set<Product> products) {
this.products = products;
}
}
package com.gpch.hotel.model;
import lombok.Data;
import javax.persistence.*;
import java.util.Set;
@Data
@Entity
@Table(name = "product")
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "product_id")
private int id;
@Column(name = "productname")
private String productname;
@Column(name = "price")
private int price;
@ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
@JoinTable(name = "product_store", joinColumns = @JoinColumn(name = "product_id"), inverseJoinColumns = @JoinColumn(name = "store_id"))
private Set<Store> stores;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getProductname() {
return productname;
}
public void setProductname(String productname) {
this.productname = productname;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public Set<Store> getStores() {
return stores;
}
public void setStores(Set<Store> stores) {
this.stores = stores;
}
}