java - Fetching GROUP_CONCAT comma separated values using Hibernate -


this query iterate module_id. ex: 1,2,3,4,5 (using group concat).

 string sql="select group_concat(module_id) module_id              sox_customer_partner_modules "           + "where customer_id= :customer_id              , partner_id= :partner_id              , status='1'"; 

my query executing fine , it's returning result 1,2,3,4,5. when i'm iterating in java , fetch first value i.e, 1

using hibernate i'm fetching records.

problem can able fetch first record. ex: 1

but want fetch 1,2,3,4,5 string.

my java code :

session session = sessionfactory.getcurrentsession(); sqlquery query = session.createsqlquery(sql); query.addscalar("module_id", hibernate.integer); query.setparameter("customer_id", customer_id); query.setparameter("partner_id", partner_id);  integer module_id=0; list<object> custmodlist = query.list();  return custmodlist.tostring(); //which returns 1.. want 1,2,3,4,5 

please needed . in advance

you should use group by, because traditionally, mysql has been rdbms allowing optional group predicates.

use query:

string sql="select group_concat(module_id) module_id          sox_customer_partner_modules "       + "where customer_id= :customer_id          , partner_id= :partner_id          , status='1'           group customer_id, partner_id"; 

of course should know better columns should identify group.

also change line:

query.addscalar("module_id", hibernate.integer); 

to:

query.addscalar("module_id", hibernate.string); 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -