Java 如何使用MySQL和Hibernate设置组\u concat\u max\u len

Java 如何使用MySQL和Hibernate设置组\u concat\u max\u len,java,mysql,sql,spring,hibernate,Java,Mysql,Sql,Spring,Hibernate,在查询中使用group concat时,我无法获取所有事件 由于组concat的默认长度为1024,所以组名为 在现有代码中设置组concat的最大长度 我这里有一个代码,我正在使用组concat和设置max len ========================================================================== DATA_QUERY="set group_concat_max_len=10024; select group_

在查询中使用group concat时,我无法获取所有事件 由于组concat的默认长度为1024,所以组名为 在现有代码中设置组concat的最大长度

我这里有一个代码,我正在使用组concat和设置max len

==========================================================================
        DATA_QUERY="set group_concat_max_len=10024;
 select group_concat(eg.name) from event_groups eg left join theatres t ON t.theatre_id = eg.theatre_id group by t.theatre_id order by t.application_name"

        Session session = getFacadeLookup().getPersistenceFacade().getHibernateSession();
        Query query = session.createSQLQuery(DATA_QUERY) and execute 

        List<Object[]> lstResult = query.list();
============================================================================
==========================================================================
DATA\u QUERY=“set group\u concat\u max\u len=10024;
从事件组中选择组(例如名称),例如左连接剧院t在t上剧院id=例如剧院id组按t剧院id顺序按t应用程序名称“
会话会话=getFacadeLookup().getPersistenceFacade().getHibernateSession();
Query Query=session.createSQLQuery(数据查询)并执行
List lstreult=query.List();
============================================================================

错误设置此处不支持组浓度最大值

首先尝试设置
组浓度最大值

session.doWork(connection -> {
    try(Statement statement = connection.createStatement()) {
        statement.execute("SET GLOBAL group_concat_max_len=10024");
    }
});
或Java 8之前的语法:

session.doWork(new Work() {
    @Override
    public void execute(Connection connection) throws SQLException {
        try (Statement statement = connection.createStatement()) {
            statement.execute("SET GLOBAL group_concat_max_len=10024");
        }
    }
});
然后才执行查询:

Query query = session.createSQLQuery(
    "select group_concat(eg.name) " +
    "from event_groups eg " +
    "left join theatres t ON t.theatre_id = eg.theatre_id " +
    "group by t.theatre_id order by t.application_name");
List<Object[]> lstResult = query.list();
Query Query=session.createSQLQuery(
“选择组名称(例如名称)”+
“来自事件组,例如”+
“在t.theatre\u id=eg.theatre\u id上左连接剧院t”+
“按t.theatre分组(按t.application\U name排序”);
List lstreult=query.List();

如果使用Hikari连接池,则可以在in
connection init sql中启动会话时设置所有会话配置值,如下所示:

spring.datasource.hikari.connection-init-sql=SET sql_require_primary_key = off;SET SESSION group_concat_max_len = 1000000;

我认为您不能这样设置会话属性。什么不能在多个查询中分割结果以绕过限制?我正在使用hibernate会话对象创建sqlQuery,因此如何设置会话组\u concat\u max\u len=1000000;在jre 1.7版本session中是否可能。doWork(连接->lamda符号当然不受jre 1.7版本的支持。您需要使用
new Work(){}
匿名类语法。session.doWork(new Work(){@Override public void execute(连接连接)抛出SQLException{try(Statement Statement=connection.createStatement(){Statement.execute(“SET GLOBAL group_concat_max_len=10024”);Statement.close();}}});工作正常谢谢:)