Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve generic resolution support in Spring Data JPA #34414

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,20 @@ private Type extractResultType(ClassInfo repositoryClassInfo, MethodInfo method)
// this is accomplished by resolving the generic type from the interface we are actually implementing
TypeVariable resultTypeVariable = resultType.asTypeVariable();
List<TypeVariable> interfaceTypeVariables = method.declaringClass().typeParameters();
if (interfaceTypeVariables.size() == 1 && interfaceTypeVariables.get(0)
.equals(resultTypeVariable)) {

int matchingIndex = -1;
for (int i = 0; i < interfaceTypeVariables.size(); i++) {
if (interfaceTypeVariables.get(i).equals(resultTypeVariable)) {
matchingIndex = i;
break;
}
}

if (matchingIndex != -1) {
List<Type> resolveTypeParameters = JandexUtil.resolveTypeParameters(repositoryClassInfo.name(),
method.declaringClass().name(), index);
if (resolveTypeParameters.size() == 1) {
return resolveTypeParameters.get(0);
if (matchingIndex < resolveTypeParameters.size()) {
return resolveTypeParameters.get(matchingIndex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Used to ensure that entity relationships work correctly
*/
@NoRepositoryBean
public interface IntermediatePostRepository<T extends ByPassHolder> extends BypassHolderRepository<T, Long> {
public interface IntermediatePostRepository<UNUSED1, T extends ByPassHolder, UNUSED2> extends BypassHolderRepository<T, Long> {

List<T> findByPostedBefore(ZonedDateTime zdt);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Used to ensure that entity relationships work correctly
*/
public interface PostRepository extends IntermediatePostRepository<Post> {
public interface PostRepository extends IntermediatePostRepository<Object, Post, Object> {

List<Post> findAllByOrganization(String organization);

Expand Down