gpt4 book ai didi

java - 在 Hibernate 中使用注释映射接口(interface)集合

转载 作者:行者123 更新时间:2023-11-29 08:52:17 25 4
gpt4 key购买 nike

我有一个名为 Rule 的接口(interface),它有 2 个实现类,它们都共享一个抽象基类。

@MappedSuperclass
public interface Rule { .. }

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class BaseRule implements Rule {

@Entity
public class ImlementingRule1 extends BaseRule {

@Entity
public class ImlementingRule1 extends BaseRule {

我在 containingRules 类中使用这个 Rule 接口(interface):

@OneToMany
@JoinColumn(name = "RULES_ID")
private List<Rule> rules;

无论我尝试什么设置,我总是以:

Caused by: org.hibernate.MappingException: Cannot use identity column key generation with <union-subclass> mapping for: mynamespace.BaseRule

最佳答案

除了使用抽象基类而不是接口(interface),我个人没有找到其他解决方案。

@OneToMany
@JoinColumn(name = "RULES_ID")
private List<BaseRule> rules;

上面写着 right here :

Annotating interfaces is currently not supported.

关于java - 在 Hibernate 中使用注释映射接口(interface)集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22172763/

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