Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 冬眠+;MSSQL查询兼容性_Sql Server_Hibernate_Hql - Fatal编程技术网

Sql server 冬眠+;MSSQL查询兼容性

Sql server 冬眠+;MSSQL查询兼容性,sql-server,hibernate,hql,Sql Server,Hibernate,Hql,我需要获取给定objectUuid的任务对象的最新“版本”。任务由其objectUuid、taskName和createdTimestamp属性标识 我有以下HQL查询: select new list(te) from " + TaskEntity.class.getName() + " te where te.objectUuid = '" + domainObjectId + "' and te.createdTimestamp = ( select max(te.create

我需要获取给定objectUuid的任务对象的最新“版本”。任务由其objectUuid、taskName和createdTimestamp属性标识

我有以下HQL查询:

select new list(te) from " + TaskEntity.class.getName() + " te 
where
te.objectUuid = '" + domainObjectId + "' and
te.createdTimestamp = ( 
    select max(te.createdTimestamp) from " + TaskEntity.class.getName() + " teSub
    where teSub.objectUuid = te.objectUuid and teSub.taskName = te.taskName
)
在H2(嵌入式)和MySQL上运行并生成正确的结果。 但是,在生产环境中将此代码安装到MS SQL Server后,出现以下错误:

除非是在一个集合中,否则集合不能出现在WHERE子句中 HAVING子句或select列表中包含的子查询,以及列 聚合是一个外部引用

我试图重写查询,但HQL似乎不支持正确的子查询。我最近的尝试是:

select new list(te) from " + TaskEntity.class.getName() + " te
inner join (
    select te2.objectUuid, te2.taskName, max(te2.createdTimestamp)
    from " + TaskEntity.class.getName() + " te2
    group by te2.objectUuid, te2.taskName
) teSub on
    teSub.objectUuid = te.objectUuid and teSub.taskName = te.taskName
where
    te.objectUuid = '" + domainObjectId + "'
当然,它在join语句之后的“(”处失败


由于这是一种非常常见的查询类型,我无法相信没有一种解决方案可以与HQL+MSSQL一起使用。

嗯,哦。这会是一个打字错误吗

max(teSub.createdTimestamp)
而不是

max(te.createdTimestamp) 
在子查询中