Customize spring data jpa repository's query to avoid fetch eager fields
09:10 25 Nov 2025

Let's say I have a spring-boot-based project, that uses spring data jpa to define entities and map them to a postgres db.

The entity has some @ManyToOne annotatated "joins" - with eager fetch set. I can not change it. Part of the project relies on this eagerness.

I want to be able to write a custom @Query("...") in my entity's repository such as I can explicitly - for this specific query - avoid the eagerness.

Is there a syntax to achieve it?

spring spring-boot spring-data-jpa jpql