public interface ScheduleRepository extends JpaRepository<Schedule, Long> {
@Query(value = "select * from truck t, " +
"(select day, end_time, latitude, longitude, start_time, " +
"truckid, is_open from schedule) s where s.truckid = t.id and day = :today ;"
, nativeQuery = true)
List<TruckLocation> getTrucksForToday(@Param("today") int today);
...
}
I have this method that does an join on two tables and returns some data, I have an object that represents this data called TruckLocation
(that does not exist in the DB). However it wont map automatically (all the attribute names match) I tried using a @SqlResultSetMapping
and a Converter
to remap the ResultSet
back together but the former doesn't operate on a method and the latter requires there to be a database representation of the resulting object which doesn't seem right for my scenario.
Is there a clean(er) way to make this query?