Issue
I have this relation in my "Persona" entity
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "persona")
private Empleado empleado;
In my "Empleado" entity I have this relation
@OneToMany(cascade = CascadeType.ALL, mappedBy = "empleado", fetch = FetchType.EAGER)
private Set<Trabajo> trabajos = new HashSet<Trabajo>();
And I have in my "Trabajo" entity this relation
@BatchSize(size = 100)
@OneToMany(cascade = CascadeType.ALL, mappedBy = "trabajo", fetch = FetchType.LAZY)
private Set<Atencion> atenciones = new HashSet<Atencion>();
And this login method provided by GoogleCode
@Override
public Persona acceder(String login, String password) {
Search s = new Search();
s.addFilterEqual("usuario", login);
s.addFilterEqual("clave", password);
return searchUnique(s);
}
When I get the result object it has loaded the objects who have the EAGER fecth, everything is OK except in the "Trabajo" entity the "Atenciones" set gets loaded either it has the LAZY fetch. How can I fix this?
In my Trabajo entity I have other @OneToMany relationships that has LAZY fetch and there still get loading objects I don't know why.
When I use the dozer mapperService, it maps all the entire tree objects and I can see all the objects that are not supposed to appear.
Solution
There is a nice explanation about lazy loading here. What you are seeing may be proxy objects. Check sql fired to verify if the data is really loaded from db.Do not worry about it if there are no queries on table related to 'Atencion'
It might be possible that your dozer mapping is accessing 'atenciones' elements which is causing the records loaded from db.If you don't want that to happen, there should be a way to exclude certain fields from mapping.
Answered By - Adisesha
Answer Checked By - David Goodson (JavaFixing Volunteer)