मेरे पास एक MySQL डेटाबेस है और मैं कुछ डेटा जेसन के रूप में पुनर्प्राप्त करना चाहता हूं।वसंत बूट में जेसन के रूप में डेटाबेस से डेटा पुनर्प्राप्त
और मेरे पास Offre
है जिसमें @OneToMany
AssociationCandidatOffre
इकाई के साथ संबंध है।
और मैं एक एपीआई जो मेरे भंडार में इस विधि calles है:
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
}
समस्या है जब मैं फोन एपीआई /offres
मुझे एक जेसन ऑब्जेक्ट वापस करने के लिए मुझे यह त्रुटि संदेश inste मिलता है विज्ञापन:
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"])
जब मैं getAssocationCandidatOffres
में @JsonIgnore
का उपयोग मैं किसी भी त्रुटि मिल न, लेकिन मैं json परिणाम में है कि संघ चाहते हैं और साथ ही।
आम तौर पर, यह किसी भी त्रुटि उत्पन्न नहीं करना चाहिए क्योंकि मेरे पास संबंध के दूसरे पक्ष में @JsonIgnore
है।
मैं इस समस्या को कैसे हल कर सकता हूं?
क्या आप सुनिश्चित हैं कि 'getAssocationCandidatOffres' सूची आबादी है? ध्यान रखें कि जब आप सूची का विस्तार करते हैं तो डीबग मोड में आईडीई पृष्ठभूमि में किसी भी आलसी लोडिंग सूची को प्राप्त करने के लिए एक क्वेरी चलाएगी। – dambros