java - how to access collection returned by jpql from ejb in managed bean -
i have app need fire jpql query sum() , func(year,...) functions, means 2 fields fetched , stored collection , collection returned managed bean. question how use collection retrieve each value. below session bean , managed bean code:
public collection getscripqtyyearwise(integer scripid) { try { collection coll=em.createquery("select sum(t.tradeexecutedquantity), func('year',t.tradedatetime) tradestock t t.scripid.scripid = :scripid group func('year',t.tradedatetime) ").setparameter("scripid", scripid).getresultlist(); return coll; }catch(exception e){return null;} }
eg of data returned: sum(qty) year 210 2011 198 2012 need extract each of values in each record returned in followinf managed bean:
objejb=(stockcommodityejbstateless) new initialcontext().lookup("stockcommoditytest"); collection coll=objejb.getscripqtyyearwise(scripid1); // how use collection?
coll
collection
of object[]
, can parse this:
(object o : coll) { object[] res = (object[]) o; object sum = res[0]; object year = res[1]; }
if want list instead of object[] can change select this:
collection coll=em.createquery("select new list(sum(t.tradeexecutedquantity), func('year',t.tradedatetime)) tradestock t t.scripid.scripid = :scripid group func('year',t.tradedatetime) ").setparameter("scripid", scripid).getresultlist();
read more here!
Comments
Post a Comment