Is it possible somehow to specify the javax.persistence.fetchgraph
or javax.persistence.loadgraph
using @QueryHint in Spring Data Jpa?
I have an entity graph
@Entity
@NamedEntityGraph(
name = "shop_with_all_associations",
includeAllAttributes = true
)
public class Shop {
@JoinColumn(name = "shop_id")
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<Member> members = new ArrayList<>();
}
And the corresponding method in the repository
@Repository
public interface ShopRepository extends JpaRepository<Shop, Integer> {
@QueryHints({@QueryHint(name = "javax.persistence.fetchgraph", value = "shop_with_all_associations")})
List<Shop> getAllWithQueryHintBy();
}
No, it's not possible. You can check your log and see the next warning when calling the method
And in the AbstractProducedQuery class, the next code section shows, that only instances of
RootGraph
could be treated as EntityGraph. But our@QueryHint
allow to pass only String as value.