java - Mapping JPA or Hibernate projection query to DTO (Data Transfer Object) -


in dao layer, have find function this

public list<?> findcategorywithsentencenumber(int offset, int maxrec) {   criteria crit = getsession().createcriteria(category.class, "cate");     crit.createalias("cate.sentences", "sent");      crit.setprojection(projections.projectionlist().     add(projections.property("title"), "title").     add(projections.count("sent.id"), "numberofsentence").     add(projections.groupproperty("title"))   );    crit.setfirstresult(offset);   crit.setmaxresults(maxrec);    return crit.list(); } 

so, in order read data, have use loop (with iterator)

list<?> result = categorydao.findcategorywithsentencenumber(0, 10); // list<dqcategorydto> dtolist = new arraylist<>();   (iterator<?> = result.iterator(); it.hasnext(); ) {   object[] myresult = (object[]) it.next();    string  title = (string) myresult[0];   long count = (long) myresult[1];     assertequals("test", title);    assertequals(1, count.intvalue());     // dqcategorydto = new dqcategorydto();   // dqcategorydto.settitle(title);   // dqcategorydto.setnumberofsentence(count);   // dtolist.add(dqcategorydto);  } 

my question is: there api, framework convert list<?> result in list of dto object (say, dqcategorydto) without using loop, iterator , calling setter/getter fill value?

you can use resulttransformer can convert alias bean (dto) properties. usage can refer hibernate docs here @ section 13.1.5


Comments

Popular posts from this blog

android - Automated my builds -

how to proxy from https to http with lighttpd -

python - Flask migration error -