I am using Spring + Hibernate and I have a particular case where I need to obtain (a list of) non-Entity objects as a result of the qu
Although the answer is correct, for someone to arrived here for similar cuestions this works for me without used @NamedNativeQuery:
public class Example {
private Long someProperty;
// getters and setters
}
To call a query or stored procedure and populate my object:
@Repository
public interface ExampleRepository extends
JpaRepository<Example,Long> {
/**
* Search Example by someProperty
*
* @param property
* @return
*/
@Query( nativeQuery = true, value = "SELECT * FROM public.my_stored_procedure(:property)")
List<Example> findByProperty(@Param("property") Long property);
}
I know this is another approach and the code is decoupled, but we get the same result.
I hope that can be useful for someone. Regards.
The name value on the @NamedNativeQuery needs to be set to "AdDailyDataEntity.aggregateRevenue". The first part (before the dot) needs to match the entity class name.