我有一个复杂的查询,如下所示
Select a.CustomerName, total = sum(b.count), tot1 = (c.count) from customer a, xyz b, stp c where <lots of joins, sub Queries, etc >
我需要将结果放入像
这样的类的实例中class CustomerTotal {
String customerName;
Integer total;
Integer total1;
}
有关如何实现上述目标的任何建议。
感谢
答案 0 :(得分:0)
您可以在AliasToBeanResultTransformer
使用
结果转换器,允许将结果转换为用户指定的类,该类将通过setter方法或与别名相匹配的字段填充。
您的查询将如下:
List<CustomerTotal> resultWithAliasedBean = s.createCriteria(Customer.class)
add here your required joins
.setProjection( Projections.projectionList()
.add(Projections.property("a.CustomerName"), "customerName")
.add(Projections.sum("b.count"), "total")
.add(Projections.property("b.count"), "total1")
.setResultTransformer( new AliasToBeanResultTransformer(CustomerTotal.class) )
.list();
的文档