Java 用JPA映射多态列表?
假设我有:Java 用JPA映射多态列表?,java,hibernate,inheritance,jpa,orm,Java,Hibernate,Inheritance,Jpa,Orm,假设我有: //inheritance annotations public abstract class Animal { private int noOfLegs; //... } //inheritance annotations public class Cat extends Animal { //cat stuff } //inheritance annotations public class Dog extends Animal { //
//inheritance annotations
public abstract class Animal {
private int noOfLegs;
//...
}
//inheritance annotations
public class Cat extends Animal {
//cat stuff
}
//inheritance annotations
public class Dog extends Animal {
//dog stuff
}
@Entity
public class House {
@OneToMany
@JoinTable(//join stuff
private List<Animal> animals;
//hose stuff
}
//继承注释
公共抽象类动物{
私密的隐蔽处;
//...
}
//继承注释
公营猫科动物{
//猫的东西
}
//继承注释
公家犬{
//狗屎
}
@实体
公屋{
@独身癖
@JoinTable(//join stuff
私人动物名录;
//软管材料
}
现在,如果我把猫和狗都放在我的房子里,并且坚持我的房子,JPA知道把猫和狗放在它们相应的表中(或者使用任何继承映射策略)吗。它知道如何在查询时收回吗?简短的回答是肯定的。但是,关于继承映射的本机hibernate支持比标准JPA更强大,并且“每个类层次结构一个表”或“每个子类一个表”映射策略比JPA更适合多态查询和关联“每个具体类的表”策略 另见:
- 以JPA映射为例