Search code examples
springspring-data-jpaspring-dataprojectionnativequery

Class-based projection with native query


Is it impossible to use class-based projection in Spring Data repository with native query? And how?

PS: I tried to use @Query(value = "select new package.Foo(id, name) from my_table, nativeQuery = true) but it does not work.


Solution

  • I found the solution. Need to use @SqlResultSetMapping, ConstructorResult and NamedNativeQuery.