l a s
l a s

Reputation: 3923

Lazy Fetching entities that are configured to use Eager Fetching

My entities are configured to use Eager Fetching. But, i have a scenario where i would want the entities to be fetched lazily. Is there a way, we can do that in code?

Thanks,

Upvotes: 0

Views: 123

Answers (1)

barsju
barsju

Reputation: 4446

Your title and the first line are conflicting. Which one is it?

If they are configured as Eager I'm pretty sure there is nothing you can do about it. The other way around is much easier, which is why you should be very careful with marking your collections with Eager.

What you might consider though is not querying the complete entity, but rather just the fields you are interested in.. You can select them as object arrays or into DTO objects directly: http://www.objectdb.com/java/jpa/query/jpql/select#Result_Classes_Constructor_Expressions_

Upvotes: 1

Related Questions