est-il possible de cartographier les classes internes au targetclass
, si possible, comment est-il fait? Je suis nouveau à cette fonctionnalité @SqlResultSetMapping
:JPA 2.1 @SqlResultSetMapping classe de liaison intérieure à targetclass
@SqlResultSetMapping(
name = "EventSurveysMapping",
classes = {
@ConstructorResult(
targetClass = Survey.class,
columns = {
@ColumnResult(name = "surveyid", type = Long.class),
})
})
Ainsi, le targetClass
Survey.class
a:
public class Survey {
private Long surveyid;
private List<SurveyQuestion> surveyquestions;
// constructor with mapped fields
}
Comment pourrais-je mapper le champ List<SurveyQuestion>
?
SurveyQuestion:
public class SurveyQuestion {
private Long surveyquestionid;
private String surveyquestion;
private List<String> surveyanswers;
}
aussi, et très similaire. Comment puis-je mapper un List<String>
?
je reçois une exception en essayant de faire la cartographie à List.class
:
@SqlResultSetMapping(
name = "EventPollsMapping",
classes = {
@ConstructorResult(
targetClass = Poll.class,
columns = {
@ColumnResult(name="pollid", type = Long.class),
@ColumnResult(name="questionid", type = Long.class),
@ColumnResult(name="pollquestion", type = String.class),
@ColumnResult(name="pollanswers", type = List.class) // this mapping is the cause of the exception
})
})
Exception:
org.eclipse.persistence.exceptions.ConversionException Exception Description: L'objet [Il est ID principal, ID unique], de classe [classe java.lang.String], n'a pas pu être converti en [interface java.util.List]
Sondage:
@XmlRootElement
@XmlType (propOrder={"pollid",
"pollquestionid",
"pollquestion",
"pollanswers"
})
public class Poll {
private Long pollid;
private Long pollquestionid;
private String pollquestion;
private List<String> pollanswers;
public Poll(){}
public Poll(Long pollid, Long pollquestionid, String pollquestion, List<String> pollanswers) {
super();
this.pollid = pollid;
this.pollquestionid = pollquestionid;
this.pollquestion = pollquestion;
this.pollanswers = pollanswers;
}
// setters & getters
}
Pourriez-vous montrer le code de la classe 'Poll' + les mappages relatifs utilisés pour' Survey' et 'SurveyQuestion'? –
Juste pour préciser, le impl. EclipseLink n'est pas Hibernate. –
@ O.Badr, a ajouté le sondage classe. La cartographie pour les questions d'enquête et d'enquête est déjà là. –