I have 3 Entity: PERSON, CAR, and PROFFESION.
@Entity
@Table(name = "PERSON")
public class Person implements Serializable {
@Id
private Long id;
@OneToMany(mappedBy = "person", fetch = FetchType.EAGER)
private List<Car> cars;
@OneToMany(mappedBy = "person", fetch = FetchType.EAGER)
private List<Profession> professions;
}
@Entity
@Table(name = "PROFESSION")
public class Profession implements Serializable {
@Id
private Long id;
@ManyToOne
@JoinColumn(name = "PERSON_ID")
private Person person;
}
@Entity
@Table(name = "CAR")
public class Car implements Serializable {
@Id
private Long id;
@ManyToOne
@JoinColumn(name = "PERSON_ID")
private Person person;
}
When i'm trying to retrieve a person with connections to two professions and one car the result is two professions and two duplicated cars.
Or if he is connected to five cars and one profession, the result is five cars and five duplicated professions.
How should I correct the mappings so I receive the right results?