Spring Data JPA-按ID绑定对象

时间:2019-03-30 23:11:22

标签: java spring hibernate spring-data-jpa

这是我的代码

@OneToMany(mappedBy = "parentTest")
@Cascade(CascadeType.ALL)
List<LanguageRecord> records = new ArrayList<>();

我想要这样的东西

@OneToMany(mappedBy = "parentTest")
@Cascade(CascadeType.ALL)
List<Long> languageRecordsIds = new ArrayList<>();

如何通过ID而不是对象进行映射?

1 个答案:

答案 0 :(得分:0)

this question被接受的答案回答了如何仅保留id引用。

要弄清特定问题的处理方式,您需要执行以下操作:

@ElementCollection
@CollectionTable(name = "LanguageRecordTable", joinColumns=(@JoinColumn(name="<Column name of field to select from in LanguageRecordTable>"))
@Column(name = "<Name of id field to join on in this table>")
List<Long> languageRecordsIds;