Skip to content

Commit

Permalink
Merge pull request #34414 from geoand/#34350
Browse files Browse the repository at this point in the history
Improve generic resolution support in Spring Data JPA
  • Loading branch information
geoand authored Jun 29, 2023
2 parents 283085f + a6a9fcd commit 7076120
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
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

0 comments on commit 7076120

Please sign in to comment.