I have a superclass Questions
and its subclass MultipleChoiceQuestions
Superclass has a field activity
I want to create a Set<MultipleChoiceQuestions>
and use OneToMany
annotation using mappedBy = "activity"
e.g.
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "activity" )
private Set<NQIMultipleChoiceQuestions> mcqQuestions = new HashSet<NQIMultipleChoiceQuestions>();
I am getting this error:
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property
However, it works fine if I create a set of superclass entities,
e.g.
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "activity")
private Set<NQIQuestions> questions = new HashSet<NQIQuestions>();
Is there a way to map to property of superclass?
Found the solution for this... :)
We can achieve this just by defining the targetEntity = ? in the OneToMany definition..
eg..
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "activity" , targetEntity=NQIQuestions.class)
private Set<NQIMultipleChoiceQuestions> mcqQuestions = new HashSet<NQIMultipleChoiceQuestions>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With