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.
I have a code here were I am using group concat and set 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();
============================================================================
error set group_concat_max_len not support here
Try setting the group_concat_max_len
first:
session.doWork(connection -> {
try(Statement statement = connection.createStatement()) {
statement.execute("SET GLOBAL group_concat_max_len=10024");
}
});
or pre-Java 8 syntax:
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");
}
}
});
And only then execute your query:
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With