使用Hibernate中的注释映射接口集合

时间:2014-03-04 13:04:33

标签: java hibernate jpa interface annotations

我有一个名为Rule的接口,其中包含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 { 

我在一个containgRules类中使用这个Rule接口:

@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

1 个答案:

答案 0 :(得分:0)

我个人没有找到任何其他解决方案,而不是使用抽象基类,而不是使用接口。

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

它陈述right here

  

目前不支持注释接口。

相关问题