If the @Query is native, the results can only be projected with an interface.
Unlike jpa queries, there is not room for select new MyProjection(... . where MyProjection would be a record
Any chance to see support for record for native queries ?
Something like:
public interface Persons extends JpaRepository<Person, Long> {
record PersonExcerpt(long id, String firstname, String lastname) {}
@Query(nativeQuery = true, value = "select id, firstname, lastname from fts_persons(?)")
List<PersonExcerpt> find(String name);
}
interface based projection are a little bit less expressive and cannot be used in Thymeleaf template engine, which does not like proxies.
Don't you think that
Session session = entityManager.unwrap(Session.class);
var mapper = DataClassRowMapper.newInstance(PersonExcerpt.class /*dynamically guessed*/);
var results = session.doReturningWork(connection -> {
// get ResultSet from query and parameters,
// iterate on ResultSet and use mapper for each row to get the instances of the the record
// return the list of instances
};
should work ?
If the
@Queryis native, the results can only be projected with an interface.Unlike jpa queries, there is not room for
select new MyProjection(.... whereMyProjectionwould be arecordAny chance to see support for record for native queries ?
Something like:
interface based projection are a little bit less expressive and cannot be used in Thymeleaf template engine, which does not like proxies.
Don't you think that
should work ?