我想让我的小动物园坚持使用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-property,但这意味着只有狗或猫才能住在我的动物园里。
有没有办法用Hibernate持久化一个有多个实现的接口集合?
发布于 2010-05-26 20:50:51
我可以猜到你想要的是继承树的映射。@继承注解是一种可行的方法。我不知道它是否适用于接口,但它肯定适用于抽象类。
https://stackoverflow.com/questions/2912988
复制相似问题