没有这样的列:MariaDB查询中的id

时间:2019-07-07 21:05:51

标签: java spring spring-boot jpa spring-data-jpa

我在JPA存储库中有此查询:

@Repository
public interface PaymentTransactionsDailyFactsRepository extends JpaRepository<PaymentTransactionsDailyFacts, Integer> {

    @Query(value = "SELECT " + 
            " COUNT(*) count, " + 
            " SUM(amount) volume, " + 
            " DATE(created_at) date, " + 
            " YEAR(created_at) year, " + 
            " MONTH(created_at) month, " + 
            " WEEK(created_at) week, " + 
            " DAY(created_at) day, " + 
            " type transaction_type, " + 
            " contract_id, merchant_id, terminal_id, " + 
            " status, card_brand, currency " + 
            " FROM payment_transactions " + 
            " WHERE status NOT IN ('pending_async','pending','pending_review','in_progress','new') AND created_at BETWEEN :start_date AND :end_date " + 
            " GROUP by date, contract_id, merchant_id, terminal_id, transaction_type, status, card_brand, currency", nativeQuery = true)
    List<PaymentTransactionsDailyFacts> generateDailyFacts(@Param("start_date") LocalDate start_date, @Param("end_date") LocalDate end_date);
}

但是当我在Spring Scheduler中执行它时,出现错误:

SQL Error: 1054, SQLState: 42S22
Caused by: java.sql.SQLSyntaxErrorException: No such column: id

当我在MariaDB中执行此查询时,它工作正常:

SELECT  COUNT(*) count,  SUM(amount) volume,  DATE(created_at) date,  YEAR(created_at) year,  MONTH(created_at) month,  WEEK(created_at) week,  DAY(created_at) day,  type transaction_type,  contract_id, merchant_id, terminal_id,  status, card_brand, currency  FROM payment_transactions  WHERE status NOT IN ('pending_async','pending','pending_review','in_progress','new') AND created_at BETWEEN '2011-04-11 00:00:01' AND '2029-04-11 00:00:00'  GROUP by date, contract_id, merchant_id, terminal_id, transaction_type, status, card_brand, currency

我试图在Spring属性文件中添加此配置:

spring.jpa.properties.hibernate.globally_quoted_identifiers=true
spring.jpa.properties.hibernate.globally_quoted_identifiers_skip_column_definitions=true
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

但是我无法解决。你能给我一些建议来解决这个问题吗?

0 个答案:

没有答案