2

我需要有关休眠查询的帮助。如果可能的话,我更喜欢使用 Criteria API,否则 HQL 是可以的。

我有一个带有 Account 对象属性的 Employee 对象,Account 有一个 Entry 对象的集合,每个 Entry 都有一个 Amount 属性。

我需要一个查询,该查询将返回所有拥有 Entry.Amount 总和小于零的帐户的员工。

有任何想法吗?

4

2 回答 2

2

如图所示:

ICriteria.CreateCriteria(typeof(Customer))
.Add(Expression.Eq("Firstname", "Steve"))
.CreateCriteria("Orders")
.Add(Expression.Gt("OrderDate", new  Datetime.Now)))
.List<Customer>();
于 2011-09-06T14:49:53.633 回答
0

万一它有帮助......这个问题是使用命名查询解决的。不确定是否可以使用 Criteria API。

询问:

select employee.* from employee
join (
    select accountid, sum(amount) as balance
    from entry group by accountid
) as accountbalances on accountbalances.accountid = employee.account
where accountbalances.balance < 0
于 2009-09-10T11:42:01.343 回答