......
@Resource
SessionFactory sessionFactory;
.............
@Test
@Transactional
public void testCityList3(){
long accountId=4L;
String hql = "select r.roleKey from Role r left join r.accounts a where r.state=0 and a.id= ?";
List<String> list=sessionFactory.getCurrentSession().createQuery(hql).setParameter(0, accountId).list();
System.out.println("list:"+list);
int i=0;
for (String ss : list) {
System.out.println((++i)+":"+ss);
}
}
@Transactional
public void testCityList2(){
long accountId=4L;
String hql = "select new map(r.roleKey as roleKey,r.id as id ,r.name as name) from Role r left join r.accounts a where r.state=0 and a.id= ?";
List<Map<String,Object>> list = sessionFactory.getCurrentSession().createQuery(hql).setParameter(0, accountId).list();
System.out.println("====>>list.size:"+list.size()+" \nlist:"+list);
for (Map<String, Object> map : list) {
System.out.println("\t\trole:"+map.get("id")+"\t"+map.get("name")+"\t"+map.get("roleKey"));
}
}
...............