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
@H_403_13@========================================================================== 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:
@H_403_13@session.doWork(connection -> { try(Statement statement = connection.createStatement()) { statement.execute("SET GLOBAL group_concat_max_len=10024"); } });
或Java 8之前的语法:
@H_403_13@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"); } } });
然后才执行您的查询:
@H_403_13@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