I started using Hibernate to do queries and I noticed that if I want to use repository to execute queries, that I have to use Entity in the repository to map the value that returned database.
Is there anyway for me to run query in any repository and return the data and map into java class with same name.
Like
@Query(value = "SELECT location_id, (3959 * acos (cos(radians(:lat)) * cos(radians(l.latitude)) * cos(radians(l.longitude) - radians(:lon)) + sin(radians(:lat)) * sin(radians(l.latitude)))) AS distance FROM location l having distance < :mile order by distance limit 0, :limitNum", nativeQuery = true)
List<LocationDistance> searchLocationByRadius(@Param("lat") double lat, @Param("lon") double lon, @Param("mile") double distance, @Param("limitNum") int limit);
So the location_id and distance field returned from Query will be auto map into LocationDistance object.