当我使用此查询时总是显示错误,为什么?我在审计类中使用 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 and
enter code here
pf.createdDate =: createdDenter code here
ate) 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/