我正在使用Spring在REST WebService应用程序上工作,显示数据工作正常,但是当我想在数据库中保存具有ManytoMany关系的对象时,我遇到了异常,我一直在寻找类似的问题,但是没有结果,这是我的代码。
Vehicule.class
@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="idVehicule")
public class Vehicule implements Serializable {
//Attributes
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idVehicule;
@Column(name = "refVehicule", unique = true)
private String refVehicule;
private double prixEstimatif;
@Temporal(TemporalType.DATE)
private Date dateCreation;
private String typeVehicule;
private String commentaire;
private int isDeleted;
@LazyCollection(LazyCollectionOption.FALSE)
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "vehicule_portes", joinColumns = { @JoinColumn(name = "id_vehicule") }, inverseJoinColumns = {
@JoinColumn(name = "id_porte") })
private List<Porte> listPortes;
}
Porte.class
@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="idPorte")
public class Porte implements Serializable {
//Attributes
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long idPorte;
@Column(name = "typePorte" , unique = true)
private String typePorte;
private String description;
private int isDeleted;
@ManyToMany(fetch = FetchType.EAGER,
mappedBy = "listPortes")
private List<Vehicule> vehicule;
}
porteController.class:
//add a new Porte
@RequestMapping(value="/portes" , method = RequestMethod.POST , consumes = MediaType.APPLICATION_JSON_VALUE)
public Porte savePorte(@RequestBody Porte porte){
return porteRepository.save(porte);
}
这是我的stackTrace:
2018-11-26 10:53:24.523 WARN 4732 --- [nio-8080-exec-1] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class com.heuliezbus.entites.Porte]]: java.lang.IllegalArgumentException: Can not handle managed/back reference 'defaultReference': back reference type (java.util.List) not compatible with managed type (com.heuliezbus.entites.Vehicule)
2018-11-26 10:53:24.528 WARN 4732 --- [nio-8080-exec-1] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class com.heuliezbus.entites.Porte]]: java.lang.IllegalArgumentException: Can not handle managed/back reference 'defaultReference': back reference type (java.util.List) not compatible with managed type (com.heuliezbus.entites.Vehicule)
2018-11-26 10:53:24.531 WARN 4732 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved exception caused by handler execution: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported
我正在使用AdvancedRestClient来测试我的webService: