我对使用JPA查询的MSSQL还是陌生的,我正在运行spring和hibernate项目,该项目在任何地方都处理该自定义查询。
代码是
@Query(value = "select min(id) as from_seq, max(id) as to_seq from tb_sync_data where vessel_id=:vessel_id and id > (select max(to_seq) from tb_sync_event where receiver_id=:receiverId and sync_status=:status)", nativeQuery = true)
List<SyncEvent> fromSeqToSeqEvent(@Param("vessel_id") final String vesselId, @Param("receiver_id") final String receiverId, @Param("status") final String status);
错误是
Caused by: java.lang.IllegalStateException: Using named parameters for method public abstract java.util.List in.ind.mds.repo.dao.SyncEventDao.fromSeqToSeqEvent(java.lang.String,java.lang.String,java.lang.String) but parameter 'Optional[receiver_id]' not found in annotated query 'select min(id) as from_seq, max(id) as to_seq from tb_sync_data where vessel_id=:vessel_id and id > (select max(to_seq) from tb_sync_event where receiver_id=:receiverId and sync_status=:status)'!
我认为嵌套选择查询会产生错误,我相信如何在嵌套查询中指定值?
谢谢!