一对多映射到超类的属性 [英] one to many mapping to a property of superclass

查看:28
本文介绍了一对多映射到超类的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个超类 Questions 及其子类 MultipleChoiceQuestions

I have a superclass Questions and its subclass MultipleChoiceQuestions

超类有一个字段activity

我想创建一个 Set 并使用 OneToMany 注释使用 mappedBy = "activity"

I want to create a Set<MultipleChoiceQuestions> and use OneToMany annotation using 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 

但是,如果我创建一组超类实体,它就可以正常工作,

However, it works fine if I create a set of superclass entities,

例如

@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... :)

我们可以通过定义 targetEntity = 来实现这一点.在 OneToMany 定义中..

We can achieve this just by defining the targetEntity = ? in the OneToMany definition..

例如...

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "activity" , targetEntity=NQIQuestions.class)    
private Set<NQIMultipleChoiceQuestions> mcqQuestions = new HashSet<NQIMultipleChoiceQuestions>();

这篇关于一对多映射到超类的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆