3 rows in set (0.00 sec)
使用List
String query = "select new List(p.code, p.value) from Dictionary p";
List list = session.createQuery(query).list();
System.out.println(list);
//结果: [[001, 四川],[002,北京],[001,四川]]
String query = "select new Map(p.code, p.value) from Dictionary p";
List list = session.createQuery(query).list();
//结果:[{1=四川, 0=001},{1=北京, 0=002},{1=四川, 0=001}]
String query = "select new Map(p.code as code, p.value as value) from Dictionary p";
List list = session.createQuery(query).list();
//结果:[{value=四川, code=001},{value=北京, code=002},{value=四川, code=001}]
String query = "select new Map(p.code as code, p.value) from Dictionary p";
List list = session.createQuery(query).list();
//结果:[{1=四川, code=001},{1=北京, code=002},{1=四川, code=001}]
select new List(p.name, p.address) from Person as p ;
select将选择出来的属性存入一个List对象中
select new ClassTest(p.name, p.address) from Person as p;
select将选择出来的属性封装成对象,前提是ClassTest支持p.name, p.address的构造函数,
select new Map(p.name as personName) from Person as p ;
select将选中的表达式命名为别名,这种用法与new Map()结合,选择出来的是Map结构,
以personName为key,将实际选择出来的值作为value