Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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_Jpa_Mapping_Entity - Fatal编程技术网

Java JPA映射:在多个关系中重用实体

Java JPA映射:在多个关系中重用实体,java,jpa,mapping,entity,Java,Jpa,Mapping,Entity,假设我有: class Unit { private TextContainer source; private List<TextContainer> targets; } 类单位{ 私有文本容器源; 私人名单目标; } 我是否可以对类TextContainer进行注释,使其在两种关系中都能工作? TextContainer必须是源或目标。您需要在单元类中注释与TextContainer的关系。大概是这样的: class Unit { @ManyToO

假设我有:

class Unit {
    private TextContainer source;
    private List<TextContainer> targets;
}
类单位{
私有文本容器源;
私人名单目标;
}
我是否可以对类TextContainer进行注释,使其在两种关系中都能工作?
TextContainer必须是源或目标。

您需要在
单元
类中注释与
TextContainer
的关系。大概是这样的:

class Unit {

    @ManyToOne(cascade=CascadeType.ALL) 
    private TextContainer source;

    @OneToMany(cascade=CascadeType.ALL) 
    private List<TextContainer> targets;
}
类单位{
@多通(级联=级联类型.ALL)
私有文本容器源;
@OneToMany(级联=级联类型.ALL)
私人名单目标;
}