[英]@Query JpaRepository, querying decimal(19,4) becomes null when mapped to DTO BigDecimal or Long
Sorry, this is my first time posting so forgive me for my formatting and details:抱歉,这是我第一次发帖,请原谅我的格式和细节:
I am having trouble with a @Query via JpaRepository我在通过 JpaRepository 使用 @Query 时遇到问题
@Repository
public interface MonthlyBillingFeesRepository extends JpaRepository<MonthlyBillingFeesEntity, String> {
@Query(value = "SELECT new com.moo.operations.backend.dto.MonthlyAggregatedBillingFeesDto(" +
"SUM(m.customMooTotalBillingFeesSummary698721), " +
"m.entryDate) " +
"FROM " +
"MonthlyBillingFeesEntity m GROUP BY m.entryDate")
public List<MonthlyAggregatedBillingFeesDto> getAllBillingFeesByMonth();
the DTO: DTO:
public class MonthlyAggregatedBillingFeesDto {
private Long customMooTotalBillingFeesSummary698721;
@Type(type="timestamp")
private Date entryDate;
public MonthlyAggregatedBillingFeesDto(Long customMooTotalBillingFeesSummary698721, Date entryDate) {
this.customMooTotalBillingFeesSummary698721 = customMooTotalBillingFeesSummary698721;
this.entryDate = entryDate;
//getters setters
It works without a problem when I put the query directly into SQL.当我将查询直接放入 SQL 时,它可以正常工作。 Also when I query via postman, it does return the entry dates properly, just not the Decimal values.
此外,当我通过 postman 查询时,它确实正确返回了输入日期,而不是十进制值。 I am not sure where the breakdown is.
我不确定故障在哪里。 I have tried to use nativeQuery as well, and nothing works.
我也尝试过使用 nativeQuery,但没有任何效果。
Ok thank you all, so I actually figured it out.好的,谢谢大家,所以我真的想通了。 Basically my column names that started with underscore _ really was causing issues with the hibernate naming strategy.
基本上,以下划线 _ 开头的列名确实导致了 hibernate 命名策略的问题。 No matter what I did, it wouldn't query the right column name.
无论我做什么,它都不会查询正确的列名。 I had to change the names of the columns to camelcase and used:
我不得不将列的名称更改为驼峰式并使用:
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
in the applications.properties file.在 applications.properties 文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.