I was exploring that topic too. I ended up using Spring Data JPA Interface-based Projections with native queries.
I created an interface, making sure the UPPERCASE part matches the DB Column names:
public interface R11Dto {
String getTITLE();
Integer getAMOUNT();
LocalDate getDATE_CREATED();
}
Then i created a repository, for an Entity (User) not related in any way to the view. In that repository i created a simple native query. vReport1_1 is my view.
public interface RaportRepository extends JpaRepository<User, Long> {
@Query(nativeQuery = true, value = "SELECT * FROM vReport1_1 ORDER BY DATE_CREATED, AMOUNT")
List<R11Dto> getR11();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…