Uploaded image for project: 'Spring Data Commons'
  1. Spring Data Commons
  2. DATACMNS-854

Custom implementation of repository fails when overriding methods containing generics

    XMLWordPrintable

    Details

      Description

      I am using the method for creating custom implementation of repositories, as described (among other places) here. This works great for just about all methods, including methods from the standard CrudRepository and PagingAndSortingRepository like Page<T> findAll(Pageable pageable). However, this does not work if the method defined in CrudRepository or PagingAndSortingRepository contains parameters with generics, like T findOne(ID id).

      Why am I doing this you ask? Well, I am trying to find a work around while waiting for DATACMNS-293. This allows me to implement the methods manually, while keeping all the goodness of the restful exposure code as-is, which given QueryDSL is suprisingly simple and I am nearly questioning the need for the solution in DATACMNS-293...

      The following patch fixes the issue for me, but I am not able to see if this has further unwanted ramifications:

      iff --git a/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java b/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java
      index 48bcdac..785c575 100644
      --- a/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java
      +++ b/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java
      @@ -356,7 +356,7 @@ class DefaultRepositoryInformation implements RepositoryInformation {
                                              return false;
                                      }
                              } else {
      -                               if (!types[i].equals(parameterType)) {
      +                               if (!types[i].isAssignableFrom(parameterType)) {
                                              return false;
                                      }
                              }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              olivergierke Oliver Drotbohm
              Reporter:
              terjestrand Terje Strand
              Last updater:
              Oliver Drotbohm
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: