我有两个实体 - Person和Car。我决定使用@ElementCollection(仅存储汽车ID )而不是使用@OneToMany关系映射它们,这样我就可以减少数据库的负载,并且在我获取Person时额外获取汽车。
但是 Hibernate 不断创建新的链接表,如'person_car_ids'。所以我的问题是 - 我如何在“汽车”表 中映射人员 ID ?
@Entity
public class Person implements Serializable {
@Id
private String id;
@ElementCollection
private Set<Long> carIds = new HashSet<>();