直接上代码:

 public virtual IList<VoucherLog> GetMaxResultVoucherLog()
        {
            string orgaizationCode = HttpContext.Current.Session["OrganizationCode"].ToString();
            return this.Session.CreateQuery("select h from VoucherLog h where h.PeopleCode in (SELECT A.Code from  User A where A.organization.Id = :orgaizationCode) Order by h.Code desc")
             .SetString("orgaizationCode", orgaizationCode)
             .SetMaxResults(1)
             .List<VoucherLog>();
        }

在代码中我用in实现过滤子查询。在写hql语句的时候我们要特别注意,hql语句中出现的属性必须和对象中的属性对应上,如果是对象的话,要使用对象的关系如:

A.organization.Id  这就说明在User这个对象中还有一个带关系的organization对象,所有赋值的时候,应严格按照关系来走。

相关文章:

  • 2022-01-31
  • 2021-12-13
  • 2021-12-09
猜你喜欢
  • 2022-01-18
  • 2022-03-04
  • 2021-11-20
  • 2021-10-26
  • 2021-10-27
相关资源
相似解决方案