How to return HashMap from JPA query?

前端 未结 3 1137
时光取名叫无心
时光取名叫无心 2020-12-30 11:58

I want to return a HashMap from JPA query like the below but I don\'t know how to fill the HashMap from this query. Actually I want to fill charts from HashMap in the fronte

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-30 12:32

    I know that it's an old question, but you can create an object to store info

    public class UserCount {
       private String username;
       private Long count;
    
       public UserCount(String user, Long count){
          this.username = user;
          this.count = count;
       }
    
    }
    

    It's important to create the constructor and to pass the parameters in the correct way.

    The JPQL became

    select my.package.UserCount(i.username, count(i.uuid) ) from schema.information i where i.entereddt between :start and :end group by i.username
    

    The query returns a List .

提交回复
热议问题