作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否可以将内部类映射到 targetclass
,如果可能的话,它是怎么做的?我是新手@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>
field ?
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 Exception Description: The object [It is Primary ID, It is unique ID], of class [class java.lang.String], could not be converted to [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
}
最佳答案
以我的经验,当我必须映射一个集合时,最后我做了这样的事情:
@OneToMany
private Set<SurveyQuestion> surveyanswers;
关于java-8 - JPA 2.1 @SqlResultSetMapping 将内部类绑定(bind)到目标类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43548730/
我是一名优秀的程序员,十分优秀!