là nó có thể ánh xạ các lớp bên trong để targetclass
, nếu có thể, nó được thực hiện như thế nào? Tôi mới đến @SqlResultSetMapping
chức năng này:JPA 2.1 @SqlResultSetMapping ràng buộc lớp bên trong để targetclass
@SqlResultSetMapping(
name = "EventSurveysMapping",
classes = {
@ConstructorResult(
targetClass = Survey.class,
columns = {
@ColumnResult(name = "surveyid", type = Long.class),
})
})
Vì vậy, các targetClass
Survey.class
có:
public class Survey {
private Long surveyid;
private List<SurveyQuestion> surveyquestions;
// constructor with mapped fields
}
Làm thế nào tôi sẽ lập bản đồ các lĩnh vực List<SurveyQuestion>
?
SurveyQuestion:
public class SurveyQuestion {
private Long surveyquestionid;
private String surveyquestion;
private List<String> surveyanswers;
}
Ngoài ra, và rất giống nhau. Làm cách nào để tôi lập bản đồ cho một List<String>
?
tôi nhận được một ngoại lệ khi cố gắng làm bản đồ để 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
})
})
Ngoại lệ:
org.eclipse.persistence.exceptions.ConversionException Exception Mô tả: Đối tượng [Nó là ID chính, là ID duy nhất], thuộc lớp [lớp java.lang.String], không thể được chuyển đổi thành [giao diện java.util.List]
Thăm dò ý kiến:
@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
}
Bạn có thể hiển thị mã của lớp 'Poll' + ánh xạ tương đối được sử dụng cho' Survey' và 'SurveyQuestion' không? –
Chỉ cần làm rõ, impl. là EclipseLink không Hibernate. –
@ O.Badr, đã thêm lớp Thăm dò ý kiến. Ánh xạ cho khảo sát và khảo sát đã có sẵn. –