I have classes with a many-to-one relationship. When I query for them using Criteria.list, the lazy fields are populated.
public class SE {
@OneToMany(fetch = FetchType.LAZY, mappedBy = "mSe")
private List<RS> mRs;
}
public class RS {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "my_join_id")
private SE mSe;
}
...
Criteria criteria = session.createCriteria(SE.class);
List<SE> myObjects = criteria.list();
// SE objects have lazy list populated. why?
How do I prevent the lazy fields from being loaded?
How do you know it is populated?
If you are looking with your debugger, it is a normal behavior because the debuger do a lot of stuff and most of the time call the getter to have a string representation of the instance. Since the getter is called, the lazy loading is triggered.
What you can do to ensure it is really lazy loaded is remove your @Transactional annotation, and you should have an error when rying to access SE in the debugger.