我有一个父类(super class) Questions
及其子类 MultipleChoiceQuestions
父类(super class)有一个字段 activity
我想创建一个Set<MultipleChoiceQuestions>
并使用OneToMany
使用 mappedBy = "activity"
进行注释
例如
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "activity" )
private Set<NQIMultipleChoiceQuestions> mcqQuestions = new HashSet<NQIMultipleChoiceQuestions>();
我收到此错误:
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property
但是,如果我创建一组父类(super class)实体,它就可以正常工作,
例如
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "activity")
private Set<NQIQuestions> questions = new HashSet<NQIQuestions>();
有没有办法映射到父类(super class)的属性?
最佳答案
找到了解决方案...:)
我们只需定义 targetEntity = ? 即可实现此目的在 OneToMany 定义中..
例如..
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "activity" , targetEntity=NQIQuestions.class)
private Set<NQIMultipleChoiceQuestions> mcqQuestions = new HashSet<NQIMultipleChoiceQuestions>();
关于hibernate - 一对多映射到父类(super class)的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4447613/