java.lang.IllegalStateException : Using named parameters

标签 java spring hql

当我使用此查询时总是显示错误,为什么?我在审计类中使用 MappedSuperclass。

@Query("select new  com.brite.domain.CurrencyConversion(ins.id,ins.contractType,ins.symbol,ins.exchange,ins.currency,ap.allocationQty,ap.createdDate,ca.baseCurrency,hd.close) from ActualPortfolio as ap JOIN  Instrument as ins on ins.id=ap.instrument.id JOIN  HistoricalData as hd on hd.instrumentId = ins.id   Join ClientAccount as ca on ca.accountId = ap.clientAccount.accountId  where ap.clientAccount.accountId =:accountId and ap.createdDate = (select MAX(pf.createdDate) as date from ActualPortfolio pf where  ap.clientAccount.accountId =:accountId and pf.createdDate =: createdDate) and hd.dateTime = (select to_char(MAX(pf.createdDate), 'YYYY-MM-DD 00:00:00') as date from ActualPortfolio pf where  ap.clientAccount.accountId =:accountId and pf.createdDate =: createdDate)")

Pojo 类的外观

        @Entity
        @EntityListeners(AuditingEntityListener.class)
        public class Transaction extends Audit {    
            private Long Id;     

        }

审计类别为

        @MappedSuperclass
        public class Audit {

            @Column(name = "createdDate", columnDefinition = "TIMESTAMP WITH TIME ZONE")
            @CreatedDate
            @JsonSerialize(using = CustomDateSerializer.class)
            private LocalDateTime createdDate;

        }

Caused by: java.lang.IllegalStateException: Using named parameters for method public abstract java.util.List com.brite.repository.InstrumentRepository.getInstrumentForCurrencyConverstion(java.lang.String,java.time.LocalDateTime) but parameter 'Optional[createdDate]' not found in annotated query 'select new com.brite.domain.CurrencyConversion(ins.id,ins.contractType,ins.symbol,ins.exchange,ins.currency,ap.allocationQty,ap.createdDate,ca.baseCurrency,hd.close) from ActualPortfolio as ap JOIN Instrument as ins on ins.id=ap.instrument.id JOIN HistoricalData as hd on hd.instrumentId = ins.id Join ClientAccount as ca on ca.accountId = ap.clientAccount.accountId where ap.clientAccount.accountId =:accountId and ap.createdDate = (select MAX(pf.createdDate) as date from ActualPortfolio pf where ap.clientAccount.accountId =:accountId andenter code here pf.createdDate =: createdDenter code hereate) and hd.dateTime =enter code here (select to_char(MAX(pf.createdDate), 'YYYY-MM-DD 00:00:00') as date from ActualPortfolio pf where ap.clientAccount.accountId =:accountId and pf.createdDate =: createdDate)'!

最佳答案

在我看来,您正在将可选参数传递给方法。这可能会引起问题。

关于java.lang.IllegalStateException : Using named parameters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57109973/

相关文章:

java - 在 HQL 中查询标量集合

java - RESTful 畅玩!框架

java - 可以使用 JOGL 创建 3D 组件吗?

Spring 交易: inner transaction changes are "rolled back" by outer transaction (or maybe jpa misuse)

java - Spring——Java项目中的微服务和docker

java - 如何在我的 Java 项目中找到不需要的 JARS

java - Hibernate 查询语言问题

sql - 如果grails中的Hibernate查询中的条件如何应用

java - 有没有办法将实时数据发送到JBOSS

java - 向 WinSCP 发送命令