How to Access Columns generated by projection criteria in Hibernate(pseudo columns)? -


this criteria returns 6 columns.
projectionlist projlist = projections.projectionlist();

    projlist.add(projections.property("se.ticker"),"ticker");     projlist.add(projections.property("cl.firstname"),"firstname");     projlist.add(projections.property("cl.middlename"),"middlename");     projlist.add(projections.property("tr.client"),"client");     projlist.add(projections.sum("tr.cumulativeqty"),"cumulativeqty");     projlist.add(projections.sum("tr.cumulativebalance"),"cumulativebalance");     projlist.add(projections.groupproperty("tr.securityid"));      criteria criteria = createentitycriteria(transactiondetails.class, "tr")             .createalias("tr.client", "cl")             .createalias("tr.security", "se")             .add(restrictions.eq("cl.id", clientid))             .setprojection(projlist);         return (list<transactiondetails>) criteria.list(); 

how access column details(data column). have given alias name of no use. please suggest me way access column data.

you have 2 options

1 > result list of array. can iterate though them , columns.

list<object[]> criteria = criteria.list();  (object[] result : results) {     string ticker = (string)result[0];     string firstname = (string)result[1];     // other properties same way  } 

2 > can specify result transformer, hibernate rest. have map columns in projections vo object columns.

in case can have vo object below.

class transactiondetailvo{     string ticker;     string firstname;     string lastname;     //other properties. these properties map alias in projection      projlist.add(projections.property("cl.firstname"),"firstname"). here `firstname`. }   criteria criteria = createentitycriteria(transactiondetails.class, "tr")             .createalias("tr.client", "cl")             .createalias("tr.security", "se")             .add(restrictions.eq("cl.id", clientid))             .setprojection(projlist)             .setresulttransformer(transformers.aliastobean(transactiondetailvo.class));   list criteria = criteria.list();  (object result : results) {     transactiondetailvo transactiondetailvo = (transactiondetailvo)result;     // access properties. } 

here example.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -