1

This is my code

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

I would like to have something like this

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

How to map by ID instead of object?

Oskar Woźniak
  • 715
  • 2
  • 10
  • 25
  • Possible duplicate of [How do I retrieve only the ID instead of the Entity of an association?](https://stackoverflow.com/questions/36212319/how-do-i-retrieve-only-the-id-instead-of-the-entity-of-an-association) – V. Lovato Mar 30 '19 at 23:39
  • Possible duplicate of [How to load only ids from Many to Many mapping tables?](https://stackoverflow.com/questions/16999997/how-to-load-only-ids-from-many-to-many-mapping-tables) – Ryan Garner Apr 04 '19 at 20:04

1 Answers1

0

The accepted answer of this question answers how to hold just id references.

To clarify what to do for your specific question, you would want to do:

@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;