public class HibernateDialectExtensions extends Object
This class defines some extensions to JPQL language, that must be registered in the HibernateSessionFactory, and can also be used in QueryDSL if needed.
This section factory declares a custom function for the support of group_concat - which is not a JPQL standard function. The implementation for this custom function depends on the target database. See GroupConcatFunction for h2 and mysql, StringAggFunction for Postgre
Syntax is as follow :
group_concat(will concatenate as expected over the column identifier.col identifier )
group_concat(will send this to the target db as 'group_concat(id1 order by id2 [asc|desc])'col identifier 1 , 'order by',col identifier 2 , ['asc|desc'])
The standard aggregate functions : count, sum, avg, min and max, used in a JPA query, cannot apply on subqueries. For instance one cannot sum((select id from entity)). The antlr parser used by Hibernate will just dismiss such nodes although the would-be SQL would run just fine on the target database.
By chance custom sql function can do so. So, by registering the standard aggregate functions as custom functions we can trick Hibernate parser into thinking that the jpa item it reads is a custom function while it will just really print a regular function in the sql output, and so offer us free support for aggregate over subqueries.
The function names are :
| Modifier and Type | Class and Description |
|---|---|
static class |
HibernateDialectExtensions.FnSupport |
| Modifier and Type | Field and Description |
|---|---|
static String |
FN_NAME_AVG |
static String |
FN_NAME_CNT |
static String |
FN_NAME_GROUP_CONCAT |
static String |
FN_NAME_MAX |
static String |
FN_NAME_MIN |
static String |
FN_NAME_SUM |
static String |
FN_NAME_WEEK |
| Modifier and Type | Method and Description |
|---|---|
static Map<String,org.hibernate.dialect.function.StandardSQLFunction> |
getH2DialectExtensions() |
static Map<String,org.hibernate.dialect.function.StandardSQLFunction> |
getMysqlDialectExtensions() |
static Map<String,org.hibernate.dialect.function.StandardSQLFunction> |
getPostgresDialectExtensions() |
public static final String FN_NAME_GROUP_CONCAT
public static final String FN_NAME_WEEK
public static final String FN_NAME_SUM
public static final String FN_NAME_CNT
public static final String FN_NAME_MIN
public static final String FN_NAME_MAX
public static final String FN_NAME_AVG
Copyright © 2010–2016 Henix, henix.fr. All rights reserved.