私はMySQLデータベースを持っており、jsonとしていくつかのデータを取得したいと思います。春のブート時にjsonとしてデータベースからデータを取得する
そして、AssociationCandidatOffre
エンティティと@OneToMany
の関係を持つエンティティOffre
があります。
と私は私のリポジトリにこの方法をcalles APIがあります。
offreRepository.findAll();
Offreをエンティティ:
@Entity
public class Offre implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "CODE_OFFRE")
private Long codeOffre;
private String titre;
@OneToMany(mappedBy = "offre")
private Collection<AssociationCandidatOffre> associationCandidatOffres;
public Collection<AssociationCandidatOffre> getAssociationCandidatOffres() {
return associationCandidatOffres;
}
public void setAssociationCandidatOffres(Collection<AssociationCandidatOffre> associationCandidatOffres) {
this.associationCandidatOffres = associationCandidatOffres;
}
//... getters/setters
}
AssociationCandidatOffreエンティティ:私が呼ぶとき
@Entity
public class AssociationCandidatOffre implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long idAssociation;
private String lettreMotivation;
private String tarifJournalier;
private Date dateDisponibilite;
@ManyToOne
private Candidat candidat;
@ManyToOne
private Offre offre;
@JsonIgnore
@XmlTransient
public Candidat getCandidat() {
return candidat;
}
@JsonSetter
public void setCandidat(Candidat candidat) {
this.candidat = candidat;
}
@JsonIgnore
@XmlTransient
public Offre getOffre() {
return offre;
}
@JsonSetter
public void setOffre(Offre offre) {
this.offre = offre;
}
//... getters/setters
}
問題がありますapi /offres
私にjsonオブジェクトを返すにはこのエラーメッセージが出ます広告:私はgetAssocationCandidatOffres
で@JsonIgnore
を使用する場合
Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: could not extract ResultSet (through reference chain: java.util.ArrayList[0]->com.***.Rekrute.entities.Offre["associationCandidatOffres"]);
nested exception is com.fasterxml.jackson.databind.JsonMappingException: could not extract ResultSet (through reference chain: java.util.ArrayList[0]->com.***.Rekrute.entities.Offre["associationCandidatOffres"])
私はすべてのエラーを取得いけないが、私は同様にJSONの結果でその関連付けをしたいです。
getOffre()
という関係の反対側に@JsonIgnore
があるので、通常これはエラーを生成しません。
どうすればこの問題を解決できますか?
'getAssocationCandidatOffres'リストに値が設定されていますか?デバッグモードのIDEは通常、リストを展開するときに遅延ロードリストをバックグラウンドで取得するためにクエリを実行します。 – dambros