【发布时间】:2020-09-17 18:59:45
【问题描述】:
我有两个具有以下属性的实体类:
class Parent {
@Id
string columnA;
string columnB;
}
class Child {
//confused here: ManyToOne with Parent class
string columnC;
string columnD;
}
我想要如下的 SQL 表:
- 父级(A列(主键),B列)
- 子级(A列(外键),C列,D列)其中,
- 主键 = (columnA, columnC) and,
- (子 -> 多对一 -> 父)关系。
问题 1:如何为 Child 创建正确的 Entity 类?
问题2:我想要一个扩展JpaRepository 的childRepository 接口。我一头雾水,如何指定复合主键?
public interface childRepository extends JpaRepository<Child, 'What to write here?'>{
}
【问题讨论】:
标签: java spring spring-boot jpa spring-data-jpa