Skip to content

Commit

Permalink
Improve generic resolution support in Spring Data JPA
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Jun 29, 2023
1 parent 8632e3e commit a6a9fcd
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 a6a9fcd

Please sign in to comment.