JPA Criteria API group_concat usage

后端 未结 3 910
萌比男神i
萌比男神i 2020-12-04 00:55

I am currently working on a report which needs a group_concat for one of the fields.

CriteriaQuery criteriaQuery = criteriaBuilder
             


        
3条回答
  •  囚心锁ツ
    2020-12-04 01:07

    Simple solution: instead of creating the whole class, just use SQLFunctionTemplate.

    new SQLFunctionTemplate(StandardBasicTypes.STRING, "group_concat(?1)")
    

    and then register this function in your own SQL dialect (eg. in constructor)

    public class MyOwnSQLDialect extends MySQL5Dialect {
    
      public MyOwnSQLDialect() {
        super();
        this.registerFunction("group_concat", new SQLFunctionTemplate(StandardBasicTypes.STRING, "group_concat(?1)"));
      }
    }
    

提交回复
热议问题