如何使用MySQL和Hibernate设置group_concat_max_len

while using group concat in query I am not able to get all the event
group name due to default length of group concat is 1024 so how I can
set max_length of group concat in existing code.

我有一个代码,我在使用group 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

错误集group_concat_max_len不支持此处

最佳答案
首先尝试设置group_concat_max_len:

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

相关文章

这篇文章主要介绍了spring的事务传播属性REQUIRED_NESTED的原...
今天小编给大家分享的是一文解析spring中事务的传播机制,相...
这篇文章主要介绍了SpringCloudAlibaba和SpringCloud有什么区...
本篇文章和大家了解一下SpringCloud整合XXL-Job的几个步骤。...
本篇文章和大家了解一下Spring延迟初始化会遇到什么问题。有...
这篇文章主要介绍了怎么使用Spring提供的不同缓存注解实现缓...