sha*_*esh 10 annotations hibernate one-to-many
我有一个超类Questions及其子类MultipleChoiceQuestions
超类有一个领域 activity
我想创建一个Set<MultipleChoiceQuestions>并使用OneToMany注释mappedBy = "activity"
例如
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "activity" )
private Set<NQIMultipleChoiceQuestions> mcqQuestions = new HashSet<NQIMultipleChoiceQuestions>();
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property
Run Code Online (Sandbox Code Playgroud)
但是,如果我创建一组超类实体,它工作正常,
例如
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "activity")
private Set<NQIQuestions> questions = new HashSet<NQIQuestions>();
Run Code Online (Sandbox Code Playgroud)
有没有办法映射到超类的属性?
sha*_*esh 18
找到了解决方案...... :)
我们可以通过定义targetEntity =来实现这一目的.在OneToMany定义中..
例如..
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "activity" , targetEntity=NQIQuestions.class)
private Set<NQIMultipleChoiceQuestions> mcqQuestions = new HashSet<NQIMultipleChoiceQuestions>();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4472 次 |
| 最近记录: |