【发布时间】:2010-05-26 12:39:07
【问题描述】:
我想用 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 持久化具有多个实现的接口集合?
【问题讨论】: