首页 > 解决方案 > 在 SpringBoot JPA 中使用 Postgres 本机查询不起作用

问题描述

我正在select * from device_analytics where extract(year from comm_mnth) = 2021 and extract(month from comm_mnth) = 8 and comm_type = 'DEVICE'sql 编辑器中尝试此查询,它按预期返回数据。但是,当我使用本机查询通过 JPA 尝试相同的查询时,它返回 null,JPA 查询中有什么问题。

@Query(value = "select * from device_analytics where extract(year from comm_mnth) =:year and extract(month from comm_mnth) =:month and comm_type =:commType", nativeQuery = true)
    DeviceAnalyticsEntity findDeviceAnlayticsEntity(@Param("month") int month, @Param("year") int year,
            @Param("commType") String commType);

// 这会返回 null

analyticsRepoRo.findDeviceAnlayticsEntity(9, 2021,"DEVICE");

TIA

标签: postgresqlspring-bootspring-data-jpajpa-2.1

解决方案


推荐阅读