Java 状态:415,错误:";不支持的媒体类型";-对于请求后的一对一-多对一关系

Java 状态:415,错误:";不支持的媒体类型";-对于请求后的一对一-多对一关系,java,spring,hibernate,one-to-many,many-to-one,Java,Spring,Hibernate,One To Many,Many To One,我已经试着解决这个问题两天了,我读了所有的东西,尝试了很多选择,但是什么都没有发生,我看不出我错在哪里。 我只需要添加一个合并其他两个表的表项。很抱歉,我的描述太长,但我只想说得详尽无遗 这是表之间的关系 这是我的代码: 用户类 import com.fasterxml.jackson.annotation.*; import javax.persistence.*; import javax.validation.constraints.Size; import java.util.Arra

我已经试着解决这个问题两天了,我读了所有的东西,尝试了很多选择,但是什么都没有发生,我看不出我错在哪里。 我只需要添加一个合并其他两个表的表项。很抱歉,我的描述太长,但我只想说得详尽无遗
这是表之间的关系

这是我的代码:
用户类

import com.fasterxml.jackson.annotation.*;
import javax.persistence.*;
import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "users")
public class User {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private int id;

@Column(name = "FirstName")
private String firstName;

@Column(name = "LastName")
private String lastName;

@OneToMany(mappedBy = "user", fetch = FetchType.EAGER)
@JsonIgnore
private List<ProductRatings> userGroups = new ArrayList<>();

public User() {}
}
import com.fasterxml.jackson.annotation.*;  
import org.hibernate.annotations.Fetch;  
import org.hibernate.annotations.FetchMode;  
import javax.persistence.*;  
import javax.validation.constraints.DecimalMax;  
import javax.validation.constraints.DecimalMin;  
import javax.validation.constraints.Size;  
import java.util.ArrayList;  
import java.util.List;  

@Entity  
@Table(name = "products")  
public class Product{  
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private int id;

@Column(name = "Name")
private String name;

@OneToMany(mappedBy = "product", fetch = FetchType.EAGER)
@Fetch(value = FetchMode.SUBSELECT)
@JsonIgnore
private List<ProductRatings> productGroups = new ArrayList<>();

public Product() {}
}
import javax.persistence.*;  
@Entity  
@Table(name = "product_ratings")  
public class ProductRatings {  

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private int id;

@Column(name = "Rating")
private int rating;

@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "UserID")
private User user;

@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "ProductID")
private Product product;

public ProductRatings() {}
}  
这是我的邮递员请求
这是请求状态

并最终在IDEA控制台中编码
2019-03-15 20:44:30.150警告7288---[nio-8080-exec-1].c.j.MappingJackson2HttpMessageConverter:未能评估类型[[simple type,class com.Team_2.producttag.models.ProductRatings]的Jackson反序列化:com.fasterxml.jackson.databind.exc.InvalidDefinitionException:无法处理托管/反向引用“defaultReference”:反向引用类型(java.util.List)与托管类型(com.u 2.producttag.models.Product)不兼容


这是由于对REST客户端的意外输入造成的。 尝试添加

内容类型:application/json

接受:application/json

在REST客户端头部分


我希望这会有所帮助。

在rest服务上,永远不要使用实体类进行数据交换。了解三层架构我想你知道我现在正在学习,不可能什么都懂
2019-03-15 20:44:30.158  WARN 7288 --- [nio-8080-exec-1] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class com.teamwork_2. producttag.models. ProductRatings]]: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot handle managed/back reference 'defaultReference': back reference type (java.util.List) not compatible with managed type (com.teamwork_2. producttag.models. Product)   

2019-03-15 20:44:30.174  WARN 7288 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported]