塔布斯:
Grandpa
GP_ID (PK)
NAME
Dad
DAD_ID (PK)
PG_ID (FK)
Children
C_ID (PK)
DAD_ID (FK)
MONEY_AMOUNT
MONEY_UNIT
类(此处省略注释):
class Grandpa
{
Long id;
String name;
Double moneyAmount; // sum of Children's money amount
String moneyUnit; // first of Children's money unit.
}
class Dad
{
Long id;
Grandpa grandpa;
}
class Children
{
Long id;
Dad dad;
Double moneyAmount;
String moneyUni;
}
我想编写一个 hql 来获取带有 sum(grandpa.dad.children.money_amount) 和 first(grandpa.dad.children.money_unit) 的 Grandpa 对象。这是我的,但它不起作用:
select gp, sum(chdn.moneyAmount) as gp.moneyAmount, first(chdn.moneyUnit) as gp.moneyUnit
from Grandpa gp, Dad dad, Children chdn
where gp.id =: chdn.dad.grandpa.id