使用休眠持久化接口集合
我想用Hibernate来维持我的litte zoo:
@Entity
@Table(name = "zoo")
public class Zoo {
@OneToMany
private Set<Animal> animals = new HashSet<Animal>();
}
// Just a marker interface
public interface Animal {
}
@Entity
@Table(name = "dog")
public class Dog implements Animal {
// ID and other properties
}
@Entity
@Table(name = "cat")
public class Cat implements Animal {
// ID and other properties
}
当我试图坚持动物园时,Hibernate抱怨道:
Use of @OneToMany or @ManyToMany targeting an unmapped class: blubb.Zoo.animals[blubb.Animal]
我知道-属性,但这意味着,只有狗或猫可以住在我的动物园里。targetEntity
@OneToMany
有没有办法用Hibernate来持久化一个接口的集合,它有一个有几个实现?