Uploaded image for project: 'Spring Data JPA'
  1. Spring Data JPA
  2. DATAJPA-1003

Projections with @Query don't work as expected when projecting to class

    Details

    • Type: Bug
    • Status: Investigating
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      When projecting to an interface everything seems to work as expected with the fields are being mapped correctly. When I attempt to project into a class (with a compatible constructor) it all seems work fine unless I use an @Query annotation where it fails with this exception:

      org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.HashMap<?, ?>] to type [uk.co.rbrt.PersonSummaryClass]
      
          // works
          PersonSummaryClass findPersonSummaryClassById(long id);
          
          // doesn't work
          @Query("SELECT name AS name, age AS age FROM Person WHERE id = :id")
          PersonSummaryClass findPersonSummaryClassByIdQuery(@Param("id") long id);
      

      Example Project: https://github.com/roberthunt/spring-data-query-projection

        Attachments

          Activity

            People

            • Assignee:
              olivergierke Oliver Gierke
              Reporter:
              roberthunt87@gmail.com Robert Hunt
              Last updater:
              Prateek Ashtikar
            • Votes:
              3 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: