2016-03-22 5 views
6

मेरे पास एक MySQL डेटाबेस है और मैं कुछ डेटा जेसन के रूप में पुनर्प्राप्त करना चाहता हूं।वसंत बूट में जेसन के रूप में डेटाबेस से डेटा पुनर्प्राप्त

और मेरे पास Offre है जिसमें @OneToManyAssociationCandidatOffre इकाई के साथ संबंध है।

और मैं एक एपीआई जो मेरे भंडार में इस विधि 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 है।

मैं इस समस्या को कैसे हल कर सकता हूं?

+0

क्या आप सुनिश्चित हैं कि 'getAssocationCandidatOffres' सूची आबादी है? ध्यान रखें कि जब आप सूची का विस्तार करते हैं तो डीबग मोड में आईडीई पृष्ठभूमि में किसी भी आलसी लोडिंग सूची को प्राप्त करने के लिए एक क्वेरी चलाएगी। – dambros

उत्तर

2

आप JSON को एक ईमानदारी के एक द्विपक्षीय संबंध को परिवर्तित नहीं कर सकते हैं। आपको अंतहीन पाश मिलता है।

JSON-Parser इकाई के साथ शुरू होता है और संबंधित AssociationCandidatOffregetAssociationCandidatOffres() के माध्यम से संबंधित पढ़ता है। प्रत्येक AssociationCandidatOffre के लिए JSON-Parser getOffre() पढ़ें और फिर से शुरू होता है। पार्सर को नहीं पता कि उसे कब खत्म होना चाहिए।

संबंधित मुद्दे