简体   繁体   中英

Map Collection of Interface using annotation in Hibernate

I have an interface called Rule with 2 implementing classes who all share one Abstract base class.

@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 { 

I'm using this Rule interface in a containgRules class as such:

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

Whatever setup I try I always end up with:

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

I personally have found no other solution than to use the abstract base class, instead of interface.

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

It states right here :

Annotating interfaces is currently not supported.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM