Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 用JPA映射多态列表?_Java_Hibernate_Inheritance_Jpa_Orm - Fatal编程技术网

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映射为例

尽管指向文档的链接可能是有用的,但您也可能希望能够解决此问题。