In JPA, is it possible to have a one-to-many relationship without creating an entity?
As an example, say I have a Fortune Cookie that has several "lucky numbers." These lucky numbers are stored in a table that is only [cookie_id, lucky_number].
In JPA, is it possible to get a list of the lucky numbers without having to create a dedicated entity for it?
This is what I tried, but it gives me an error for Use of @OneToMany or @ManyToMany targeting an unmapped class
@Entity
@Table(name = "FORTUNE_COOKIE")
class FortuneCookie {
@Id
@Column(name = "ID")
Integer id;
@Column(name = "MESSAGE")
String message;
@OneToMany
@JoinTable(name = "LUCKY_NUMBERS", joinColumns = {@JoinColumn(name = "COOKIE_ID")})
List<Integer> luckyNumbers;
}