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
Jpa 使用@SecondaryTables,但字段本身在单独的类中_Jpa - Fatal编程技术网

Jpa 使用@SecondaryTables,但字段本身在单独的类中

Jpa 使用@SecondaryTables,但字段本身在单独的类中,jpa,Jpa,我的实体分布在不同的表中,我最常用的方法是使用@SecondaryTables。但是我不喜欢使用@SecondaryTables的地方是,第二个/第三个表的字段也必须在同一个实体Java类中。因为第二个/第三个表有很多字段,所以将它们放在一起将使其成为一个庞大的类 有没有一种方法,我可以使用@SecondaryTables,但实际上将字段放在不同的类中。最棒的是有这样的东西 @SecondaryTables({ @SecondaryTable(name="Table2",

我的实体分布在不同的表中,我最常用的方法是使用@SecondaryTables。但是我不喜欢使用@SecondaryTables的地方是,第二个/第三个表的字段也必须在同一个实体Java类中。因为第二个/第三个表有很多字段,所以将它们放在一起将使其成为一个庞大的类

有没有一种方法,我可以使用@SecondaryTables,但实际上将字段放在不同的类中。最棒的是有这样的东西

 @SecondaryTables({
    @SecondaryTable(name="Table2", 
        pkJoinColumns=@PrimaryKeyJoinColumn(name="ID_2"), class="someclass")
})
但JPA并没有提供这样的便利 它只提供class=“someclass”属性


那么,有什么方法可以实现我的愿望吗?

您最好使用可嵌入的:

@Entity
public class SomeEntity {

    @Embedded
    private SomeOtherClass someOtherClass; //mappings for table 2
}

@Embeddable
public class SomeOtherClass {

    // define columns from table 2
    @Column(table = "Table2")
    public String someColumn;
}