加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何使用MySQL和Hibernate设置group_concat_max_len

发布时间:2020-12-15 01:42:44 所属栏目:大数据 来源:网络整理
导读: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 ====

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读