How to get <String, List> in hql as a map

I am using hibernate. I have a table as shown below.

department  | employee 
-----------------------
Dep1        |   Tom
Dep2        |   Syam
Dep2        |   Teakey
Dep2        |   Sam
-----------------------

My intention is to get the desired department list, such as a map ( Map<String,List<Department>>), as shown below.

{
  Dep1: [Tom],
  Dep2: [Syam,Teakey,sam]
}

Is there a way to achieve this in hql in a single query. I tried as shown below. But did not work.

select new map(d.department as dept, new list(d.employee as  emp) from Department d group by d.department;

Am I mistaken in the concept of a request?

+4
source share

Source: https://habr.com/ru/post/1598235/


All Articles