【发布时间】:2019-07-19 09:56:36
【问题描述】:
当我使用这个查询时总是显示错误,为什么?我在审计类中使用 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;
}
引起:java.lang.IllegalStateException:使用命名参数 方法公共抽象 java.util.List com.brite.repository.InstrumentRepository.getInstrumentForCurrencyConverstion(java.lang.String,java.time.LocalDateTime) 但在带注释的查询中找不到参数“Optional [createdDate]” '选择新的 com.brite.domain.CurrencyConversion(ins.id,ins.contractType,ins.symbol,ins.exchange,ins.currency,ap.allocationQty,ap.createdDate,ca.baseCurrency,hd.close) 从 ActualPortfolio as ap JOIN Instrument as ins on ins.id=ap.instrument.id JOIN HistoricalData as hd on hd.instrumentId = ins.id 在 ca.accountId 上以 ca 身份加入 ClientAccount = 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 herepf.createdDate =: createdDenter code hereate) 和 hd.dateTime =enter code here(选择 to_char(MAX(pf.createdDate), 'YYYY-MM-DD 00:00:00') 作为日期从 ActualPortfolio pf 其中 ap.clientAccount.accountId =:accountId 和 pf.createdDate =: createdDate)'!
【问题讨论】:
-
请贴出带注释的方法签名。
-
可能你的存储库参数 createdDate 没有注解 @Param("createdDate") 或者参数名称与 hql 中的名称不同
-
正如下面的答案中提到的,您使用可选的创建日期作为参数。更改它以允许展开的日期对象。但是 yiu 还没有发布你的 java 部分代码。因此,请更正您的问题,以便人们帮助您。
-
您应该在@Query 之后添加存储库方法签名
-
您最好删除诸如“从 ActualPortfolio as ap JOIN Instrument as ins on ins.id=ap.instrument.id”之类的结构。您可以改用“from ActualPortfolio ap JOIN ap.instrument ins”或“from ActualPortfolio ap, Instrument ins where ins.id=ap.instrument.id”