spring-projects / spring-projects/spring-data-jpa
Allow generic type parameter (no-args subclassing) for QuerydslRepositorySupport
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3.3k
- Forks
- 1.6k
- PR merge metrics
- No merged PRs in 30d
Description
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.)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading QuerydslRepositorySupport and the compatibility context in #718, then inspect how GenericTypeResolver, ResolvableType, or TypeInformation are used elsewhere. Evaluate generic type resolution, the existing super(Class) constructor, and getBuilder() typing. Done means a no-argument generic subclassing path is defined without breaking the existing constructor or its behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100