How to do i get driver id and driver name separately?
String hql="select count(tx.driver.driverid),tx.driver.drivername from Transaction tx group by driver";
return (List)hibernateTemplate.find(hql);
service:
List list=driverService.groupby();
Iterator it=list.iterator();
while(it.hasNext())
{
Object obj=(Object)it.next();
System.out.println(obj);
}
result :
[Ljava.lang.Object;@1e65f750
[Ljava.lang.Object;@36d591df
1) Create a result class:
package my.package;
public class DriverResultClass{
private Integer count;
private String name;
public DriverResultClass(Integer count, String name){
// set fields
}
}
2) Alter your query:
select new my.package.DriverResultClass(count(tx.driver.driverid),tx.driver.drivername)
from Transaction tx
group by tx.driver.drivername
3) Change list type:
(List<DriverResultClass>)hibernateTemplate.find(hql)
Hibernate will not automatically populate the POJO object and wont need to extract manually from a List of Object arrays.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.