是否有可能将内部类映射到targetclass
,如果可能的话,它是如何完成的?我是新来这个@SqlResultSetMapping
功能:JPA 2.1 @SqlResultSetMapping绑定内部类到目标类
@SqlResultSetMapping(
name = "EventSurveysMapping",
classes = {
@ConstructorResult(
targetClass = Survey.class,
columns = {
@ColumnResult(name = "surveyid", type = Long.class),
})
})
所以targetClass
Survey.class
有:
public class Survey {
private Long surveyid;
private List<SurveyQuestion> surveyquestions;
// constructor with mapped fields
}
我怎么会映射List<SurveyQuestion>
场?
SurveyQuestion:
public class SurveyQuestion {
private Long surveyquestionid;
private String surveyquestion;
private List<String> surveyanswers;
}
而且,和非常相似。我将如何映射List<String>
?
我想什么时候做映射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
})
})
例外:
org.eclipse.persistence.exceptions.ConversionException异常 说明:对象[它是Primary ID,它是唯一ID],类 [class java.lang.String],无法转换为[interface java.util.List]
投票:
@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
}
您能否显示'Poll'类的代码+用于'Survey'和'SurveyQuestion'的相关映射? –
只是为了澄清,impl。是EclipseLink而不是Hibernate。 –
@ O.Badr,添加了投票类。调查和调查问题的映射已经存在。 –