Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/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
Nhibernate 将查询转换为HQL时遇到问题_Nhibernate_Hql - Fatal编程技术网

Nhibernate 将查询转换为HQL时遇到问题

Nhibernate 将查询转换为HQL时遇到问题,nhibernate,hql,Nhibernate,Hql,我是HQL的新手,一般来说是nHibernate,目前正在开发一个简单的应用程序来了解更多信息 不过,我在尝试将以下SQL表示为HQL时遇到了问题,如果有任何想法,我将不胜感激 问题是: select * from parent p where p.id in (select p.parentid from child c where c.createdby = 2) and (select top 1 createdby from child where parentid = p.id o

我是HQL的新手,一般来说是nHibernate,目前正在开发一个简单的应用程序来了解更多信息

不过,我在尝试将以下SQL表示为HQL时遇到了问题,如果有任何想法,我将不胜感激

问题是:

select * from parent p
where p.id in (select p.parentid from child c where c.createdby = 2)
and
(select top 1 createdby 
 from child where parentid = p.id order by createdon desc) != 2

不能保证第二部分,但也许这可以让你更接近目标。我将parentid比较替换为多对一引用。任何都应该在hql中工作

select p from parent p 
    where p in (select c.ParentReference from child c 
        where c.createdby = :twoparameter)
    and :twoparameter = (select top 1 c.createdby from child 
        where c.ParentReference = p order by p.createdon desc)

谢谢-这让我走上了正确的道路。我无法使用Top,但像这样重写查询似乎成功了:

select p from Parent p where p.ID in 
  (select c.parent.Id from Child c where c.CreatedBy = "+user.ID+") 
   and "+ user.ID +" = (select max(c.CreatedBy) 
from Child c 
where child.parent.ID = parent.ID
请原谅讨厌的字符串连接-下一步是使用参数化的HQL清理它