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