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

Projections not handled correctly when Optional is used as wrapping return type

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.10.2 (Hopper SR2), 1.11 M1 (Ingalls)
    • Component/s: None
    • Labels:
      None
    • Sprint:
      Ingalls M1

      Description

      When using Optional return type and JPQL projection to create an object (not an Entity type)
      The following exception is thrown:

      org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.Optional<?>] to type [com.cookies.domain.dto.AuthenticationPrincipal]
      

      An exaple repository is:

      @Repository
      public interface UserPrincipalRepository extends CrudRepository<UserAccountPair, String> {
       
          @Query(value = "SELECT " +
                  "new xxx.AuthenticationPrincipal(u.id, u.email, u.password, u.enabled) " +
                  "FROM ApiUser u "
                  + "WHERE LOWER(u.email) = LOWER(?1)")
          Optional<AuthenticationPrincipal> findUserForAuthentication(String string);
      }
      

      In previous versions this was working as expected.

        Attachments

          Activity

            People

            Assignee:
            olivergierke Oliver Drotbohm
            Reporter:
            maximos@cookies-app.com Maximos Sapranidis
            Last updater:
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: