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

Query methods with dynamic projections which return Optional, Stream or Page throw NoSuchElementException

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 1.11.7 (Ingalls SR7)
    • Component/s: Core
    • Labels:
      None
    • Environment:
      Windows 10 Pro, Java 8

      Description

      Query methods with dynamic projections, which return Optional, Stream or Page, throw NoSuchElementException

      For example:

      public interface CommentRepo extends JpaRepository<Comment, Integer> {
      	// doesn't work - throw NoSuchElementException
      	<T> Optional<T> findByUserName(String name, Class<T> type);
      	<T> Page<T> getAllByTextLike(Pageable pageable, String text, Class<T> type);
              <T> Stream<T> findStreamByTextLike(String text, Class<T> type);
      }
      

      Project example and tests

      P.S. Also the documentation has an error in the Dynamic projections topic - the repo method must start with type parameter:

      interface PersonRepository extends Repository<Person, UUID> {
      
         <T> Collection<T> findByLastname(String lastname, Class<T> type);
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                schauder Jens Schauder
                Reporter:
                Cepr0 Sergei Poznanski
                Last updater:
                Mark Paluch
              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: