java - Retrieve joined table results from HQL without looping -
i'm trying retrieve joined tables result database , current code this.
query
select a.name,a.employeeno,b.status,b.amount tbemployee left join tbtransact b on a.employeeno = b.employeeno b.status = '7'
code
dbservice dbsrvc = dbserviceimpl(); list<employeeform> formlist = new arraylist<employeeform>(); list<object[]> list = dbsrvc.executelistsqlquery(query, params); for(object[] row: list){ employeeform form = new employeeform(); form.setempno(row[0]); form.setname(row[1]); form.setstatus(row[2]); form.setamount(row[3]); formlist.add(form); }
is there better way this? retrieve list straight employeeform?
this dbservice method
public list executelistsqlquery(string squery, map parameters) { // --- employeedb service = (employeedb) runtimeaccess.getinstance().getservicebean( dbname); try { service.begin(); session session = service.getdataservicemanager().getsession(); sqlquery query = session.createsqlquery(squery); query.setproperties(parameters); list list = query.list(); service.commit(); // --- return list; } catch (exception ex) { logger.warn("error executing query", ex); service.rollback(); } return null; }
Comments
Post a Comment