简体   繁体   English

带有投影的休眠条件未选择数据

[英]Hibernate Criteria with projection is not picking data

I am using Hibernate criteria and projection to get distinct values as shown below: 我正在使用休眠条件和投影来获得不同的值,如下所示:

Criteria criteria = this.getSession().createCriteria(CmError.class);

ProjectionList projList = Projections.projectionList();
projList.add(Projections.property("router"));
projList.add(Projections.property("slot"));
criteria.setProjection(Projections.distinct(projList));

I am using result Transformer with Projection to get list of distinct values 我正在将结果Transformer与Projection一起使用以获取不同值的列表

List<CmError> cm =  criteria.setResultTransformer(Transformers.aliasToBean(CmError.class)).list();

What i am seeing is that all the field values for the list is null while the size of list is correct, meaning number of records i am expecting to return from same distinct SQL query is same as size of the CmError list but data inside list is not populating and returning null when I iterate over the list. 我看到的是列表的所有字段值均为null,而列表的大小正确,这意味着我希望从相同的不同SQL查询返回的记录数与CmError列表的大小相同,但列表中的数据为遍历列表时不填充并返回null。

Not sure what i am missing. 不知道我在想什么。

Try to change it to: 尝试将其更改为:

projList.add(Projections.property("router"), "router");
projList.add(Projections.property("slot"), "slot");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM