I've been trying to optimize the way hibernate achieve some information, but I can't understand next issue.
I've one entity like this
public class AnoEmp{
//bi-directional many-to-one association to Empleado
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="ID_EMPLEADO", nullable=false, insertable=false, updatable=false)
private Empleado empleado;
}
...
And another one like this
public class Empleado{
//bi-directional many-to-one association to AnoEmp
@JsonIgnore
@OneToMany(mappedBy="empleado", fetch=FetchType.LAZY)
private List<AnoEmp> anosEmp;
...
Althoug it's eager (and it has to be like that) It performs N + 1 queries one for the list of AnoEmp and one per Empleado. But it could be done with just one query (as I expected becouse of @eager)
I found this Why hibernate perform two queries for eager load a @OneToOne bidirectional association? but can't get mine running properly. Any suggestion? Thank you very much.