How to enforce lazy loading of entities on certain conditions
Posted
by Samuel
on Stack Overflow
See other posts from Stack Overflow
or by Samuel
Published on 2010-06-16T16:24:52Z
Indexed on
2010/06/16
16:42 UTC
Read the original article
Hit count: 198
We have an JPA @Entity class (say User) which has a @ManyToOne reference (say Address) loaded using the EAGER option which in turn loads it's own @ManyToOne fields (say Country) in a EAGER fashion.
We use the EntityQuery interface to count the list of User's based on a search criteria, during such a load all the @ManyToOne fields which have been marked as EAGER get loaded. But in order to perform a EntityQuery.resultCount(), I actually don't need to load the @ManyToOne fields. Is there a way to prevent loading of the EAGER fields in such cases so that we can avoid the unnecessary joins?
© Stack Overflow or respective owner