I've got two different scenarios where I have to retrieve data from one or two entities that have a relation between them.
@Entity
@Table
public class Level2 {
@Id
@Column(name = "id_level_2")
private Integer idLevel2;
@Column(name = "id_level_1")
private Integer idLevel1;
@ManyToOne
@JoinColumn(name = "id_level_1", referencedColumnName = "id_level_1", insertable = false, updatable = false)
private Level1 level1;
Case A) Just want to retrieve de level2 without Level1 information, just the two ids. Case B) All the Level2 with the Level1 information.
This works but I am wondering if it is a good practice.
Thanks