我在存储库中遇到这个奇怪的问题,当我在同一控制器中连续执行2个数据库查询时,返回的所有结果都与第一个数据库查询相同。
示例:如果我先调用getPredictedValue()然后再调用getCalled(),则根据这两个函数的调用顺序,第二个函数调用将获得与第一个调用相同的结果。
@Repository
public interface SomeRepository extends PagingAndSortingRepository<SomeObject, Integer> {
@Query(nativeQuery=true, value="SELECT SUM(c.count_of_something) AS num_of_something, " +
"TO_CHAR(c.inserted_at, 'HH24:00:00') AS hour_of_the_day " +
"FROM some_table c " +
"GROUP BY TO_CHAR(c.inserted_at, 'HH24:00:00') " +
"ORDER BY TO_CHAR(c.inserted_at, 'HH24:00:00')")
public List<SomeObject> getPredictedValue();
@Query(nativeQuery=true, value="SELECT COUNT(c.*) AS num_of_something, " +
"TO_CHAR(c.inserted_at, 'HH24:00:00') AS hour_of_the_day " +
"FROM some_table c " +
"GROUP BY TO_CHAR(c.inserted_at, 'HH24:00:00') " +
"ORDER BY TO_CHAR(c.inserted_at, 'HH24:00:00')")
public List<SomeObject> getCalled();
}