我有一个超类Questions
及其子类MultipleChoiceQuestions
超类有一个字段activity
我想创建一个Set<MultipleChoiceQuestions>
并使用OneToMany
注释使用mappedBy = "activity"
e.g.
@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
但是,如果我创建一组超类实体,它就可以正常工作,
e.g.
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "activity")
private Set<NQIQuestions> questions = new HashSet<NQIQuestions>();
有没有办法映射到超类的属性?
找到了这个问题的解决方案...:)
我们只需定义 targetEntity = ? 即可实现此目的在 OneToMany 定义中..
eg..
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "activity" , targetEntity=NQIQuestions.class)
private Set<NQIMultipleChoiceQuestions> mcqQuestions = new HashSet<NQIMultipleChoiceQuestions>();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)