2011-05-21 81 views
1
 
Customer{ 
    String customerName 
    @OneToMany 
    Set users; 
} 
User{ 
    String userName; 
} 

当我这样做:HQL concat函数

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

休眠不返回的结果我的预期。

+4

你期待什么? – Tahbaza 2011-05-21 02:00:12

+0

CONCAT()不会合并来自多个记录的值,而是从每个记录的多个参数中合并值。例如:concat(firsname,'',lastname)可能会返回特定记录,如“John Doe”。 – Brian 2011-05-21 14:12:35

回答

-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;