Spring Data JPA Fetching -


is there way define spring data specification (returning jpa predicate) sole purpose perform eager fetching?

i have entity defines various relationships using lazy loading, there several queries want return entire entity representation including related collections, criteria of these queries may vary. i've seen few posts (e.g. on spring forum) discuss potential introduction of fetch groups, ideal solution; however, since not yet part of jpa spec, spring data not provide support it.

i'm looking reusable way perform eager fetching on variety of dynamic queries.

for example, i've considered developing reusable specification sole purpose perform eager loading, , combined other specifications, e.g:

private static specification<myentity> eager() {      return new specification<myentity>() {          @override         public predicate topredicate(root<myentity> root, criteriaquery<?> query, criteriabuilder cb) {             (pluralattribute<? super myentity, ?, ?> fetch : root.getmodel().getpluralattributes()) {                 root.fetch(fetch, jointype.left);             }             query.distinct(true);             return null;         }      }; } 

the goal of specification reuse in various queries, e.g:

repository.findall(where(eager()).and(othercriteria).or(othercriteria)); 

however, eager fetching specification not true predicate, returns null, , cause obvious problems (i.e. nullpointerexceptions) when chained other predicates.

(note predicate alone work expected; i.e. following query fetch: repository.findall(eager());).

is there appropriate non-null predicate can returned "eager" specification, or there other reusable approaches triggering eager fetches using spring data jpa specifications (without having tack eager load onto specification)?

we have improved handling of null specifications , predicates in course of fixing datajpa-300. might wanna give 1.4 snapshots try , see how affects scenario.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -