spring-projects / spring-projects/spring-data-jpa

Allow generic type parameter (no-args subclassing) for QuerydslRepositorySupport

Open
#4,300 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.