gpt4 book ai didi

hibernate - 一对多映射到父类(super class)的属性

转载 作者:行者123 更新时间:2023-12-03 06:37:46 24 4
gpt4 key购买 nike

我有一个父类(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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com