QuerydslRepositorySupport still needs the domain class passed into the constructor:
class MemberRepositoryImpl extends QuerydslRepositorySupport {
MemberRepositoryImpl() { super(Member.class); }
}
The rest of Spring Data already infers the domain type from the repository generics
(DefaultRepositoryMetadata reads getTypeArguments() off Repository<T, ID>), so this base class
seems to be the one place where you still have to pass the type by hand.
I'd like to subclass without that constructor argument, taking the type from a generic parameter instead:
class MemberRepositoryImpl extends QuerydslRepositorySupport<Member> {}
The type could be resolved with GenericTypeResolver (or the ResolvableType / TypeInformation
utilities that are already used elsewhere), and getBuilder() could return PathBuilder<Member> instead
of PathBuilder<?>. It would also drop the constructor boilerplate and rule out passing a wrong
Class<?> by accident.
Would it be possible to add this while keeping the existing super(Class) constructor for compatibility?
I saw #718 mention the explicit constructor was introduced to pin getBuilder() to a single domain type,
but that seems equally achievable through the generic parameter, so I'm not sure whether the explicit form
is a hard requirement or just the original default.
(I know QuerydslPredicateExecutor already covers a lot of cases. This is specifically about the
QuerydslRepositorySupport base used for arbitrary join/projection queries, where the constructor is the
remaining bit of friction.)
QuerydslRepositorySupportstill needs the domain class passed into the constructor:The rest of Spring Data already infers the domain type from the repository generics
(
DefaultRepositoryMetadatareadsgetTypeArguments()offRepository<T, ID>), so this base classseems to be the one place where you still have to pass the type by hand.
I'd like to subclass without that constructor argument, taking the type from a generic parameter instead:
The type could be resolved with
GenericTypeResolver(or theResolvableType/TypeInformationutilities that are already used elsewhere), and
getBuilder()could returnPathBuilder<Member>insteadof
PathBuilder<?>. It would also drop the constructor boilerplate and rule out passing a wrongClass<?>by accident.Would it be possible to add this while keeping the existing
super(Class)constructor for compatibility?I saw #718 mention the explicit constructor was introduced to pin
getBuilder()to a single domain type,but that seems equally achievable through the generic parameter, so I'm not sure whether the explicit form
is a hard requirement or just the original default.
(I know
QuerydslPredicateExecutoralready covers a lot of cases. This is specifically about theQuerydslRepositorySupportbase used for arbitrary join/projection queries, where the constructor is theremaining bit of friction.)