我想使用Hibernate持久化我的小动物园:
@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]
我知道@OneToMany
的targetEntity
属性,但这意味着我的动物园里只能有狗或者猫。
是否有一种方法可以使用Hibernate持久化一个包含多个实现的接口集合?
AbstractAnimal
没有实现接口Animal
? - maxxyme