9

Acording to https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#projection.dynamic i need to implement generic method findAll, is there any way to do it without @Query annotation? I have tried this way:

<T> List<T> findAll(Class<T> type);

But I'm getting:

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type
pustypawel
  • 331
  • 2
  • 17
  • 1
    No need to implement findAll() method. You can use the one provided by spring repository – Afridi Jan 25 '18 at 11:14
  • I don't think that I'm able to cast Hibernate Entity to projection interface/dto – pustypawel Jan 25 '18 at 11:48
  • So you changed return type (default methods cover List and - in case of JPARepository - Page). There is another way though - if you really want List, you can rename your repo method to findAllBy or just findBy. The trick is, findBy returns all entities, and everything between find and By is ignored, as long as it starts with uppercase letter. This is also workaround for all "findByXYZ" predefined methods, like findById - you can just use findSomethingById or findAllById. – NoMercyIncluded Nov 27 '19 at 12:37

1 Answers1

7

Problem solved

<T> Set<T> findBy(Class<T> type);

Did work ... :)

pustypawel
  • 331
  • 2
  • 17