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

ConverterNotFoundException when invoking a method that expects a parameter interface

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.11 M1 (Gosling)
    • Component/s: None
    • Labels:
      None

      Description

      Hello,

      I have my repositories to work with interfaces, instead of entity classes, like this:

      @Repository(value = ProductRepository.NAME)
      @RepositoryRestResource(itemResourceRel = ProductModelDefinition.NAME, path = ProductModelDefinition.NAME, collectionResourceRel = ProductModelDefinition.NAME)
      public interface ProductRepository extends BaseCatalogableEntityRepository<ProductModelDefinition, Long> {
      
          @RestResource(exported = false)
          Page<ProductModelDefinition> findAllByCatalogVersionAndVariantTypeIsNotNull(@Param("catalogVersion") final CatalogVersionModelDefinition catalogVersion,
                                                                                      final Pageable pageable);
      }
      

      and it all works fine until I try to call the method findAllByCatalogVersionAndVariantTypeIsNotNull over rest. Then I get this exception:

      2015-02-02 18:53:09,958 org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/storefront].[restDispatcherServlet] [http-nio-8112-exec-7] ERROR: Servlet.service() for servlet [restDispatcherServlet] in context with path [/storefront] threw exception [Request processing failed; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type java.lang.String to type @org.springframework.data.repository.query.Param com.nemesis.platform.core.definition.catalog.CatalogVersionModelDefinition] with root cause
      org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type java.lang.String to type @org.springframework.data.repository.query.Param com.nemesis.platform.core.definition.catalog.CatalogVersionModelDefinition
       at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:311)
       at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:192)
       at org.springframework.data.repository.support.ReflectionRepositoryInvoker.prepareParameters(ReflectionRepositoryInvoker.java:214)
       at org.springframework.data.repository.support.ReflectionRepositoryInvoker.invokeQueryMethod(ReflectionRepositoryInvoker.java:179)
       at org.springframework.data.rest.webmvc.RepositorySearchController.executeQueryMethod(RepositorySearchController.java:278)
       at org.springframework.data.rest.webmvc.RepositorySearchController.executeSearch(RepositorySearchController.java:168)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      

      I tried to register a custom converter (from String to CatalogVersionModelDefinition), but I only have access to the string parameter and this means I have to register converters for all the entities. If I map the converter to the base interface (CatalogVersionModelDefinition extends another interface) it doesn't get invoked.

      Maybe the best solution would be to call the registered RepositoryMetadata::findDomainClass() method before searching in the conversion service.

        Attachments

          Activity

            People

            Assignee:
            olivergierke Oliver Drotbohm
            Reporter:
            ptahchiev Petar Tahchiev
            Last updater:
            Oliver Drotbohm
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: