HQL concat函数

时间:2011-05-21 01:46:57

标签: java sql hibernate hql

Customer{
  String customerName
  @OneToMany
  Set users;
}
User{
  String userName;
}

当我这样做时:

select c.customerName as customerName ,concat(u.userName) as userNames from Customer c join c.users as u

hibernate不会返回我期望的结果。

1 个答案:

答案 0 :(得分:-1)

不幸的是,hibernate没有组合字符串的SQL聚合函数。对此没有标准的SQL聚合函数,因此每个数据库都倾向于拥有它自己的。一个例子是NexusDB 3.x的LIST(),它编译集合中以逗号分隔的非空值列表。

SELECT c.customerName as customerName , LIST(u.userName) as userNames 
FROM Customer c 
JOIN c.users as u
GROUP BY c.customerName;