Hibernate Criteria Transformers.aliasToBean 未填充正确的值
我试图通过加入我的实体类来创建 BO,
Criteria criteria = session.createCriteria(Report.class,"r");
criteria
.createAlias("template", "t")
.createAlias("constituents", "rc")
.createAlias("rc.entity", "pe")
.createAlias("pe.model", "m")
.createAlias("pe.scenario", "s")
.setProjection(Projections.projectionList()
.add( Projections.property("r.Id"))
.add( Projections.property("t.Typ"))
.add( Projections.property("pe.bId"))
.add( Projections.property("m.model"))
.add( Projections.property("s.decay"))
).setMaxResults(100)
.addOrder(Order.asc("r.Id"))
.setResultTransformer(Transformers.aliasToBean(BO.class));
但我得到 100 个空 BO,即所有属性均为 null 我的 BO 如下
public class BO implements Serializable {
private static final long serialVersionUID = 1L;
private int Id;
private String Typ;
private String bId;
private String model;
private String decay;
Getters and Setters
......
当我删除行 aliasToBean 并迭代 Object[] 时,我可以看到获取的正确值 请指导我...
I am trying to create BO by joining my entity classes
Criteria criteria = session.createCriteria(Report.class,"r");
criteria
.createAlias("template", "t")
.createAlias("constituents", "rc")
.createAlias("rc.entity", "pe")
.createAlias("pe.model", "m")
.createAlias("pe.scenario", "s")
.setProjection(Projections.projectionList()
.add( Projections.property("r.Id"))
.add( Projections.property("t.Typ"))
.add( Projections.property("pe.bId"))
.add( Projections.property("m.model"))
.add( Projections.property("s.decay"))
).setMaxResults(100)
.addOrder(Order.asc("r.Id"))
.setResultTransformer(Transformers.aliasToBean(BO.class));
I am getting 100 empty BO i.e. all properties are null
My BO is as follows
public class BO implements Serializable {
private static final long serialVersionUID = 1L;
private int Id;
private String Typ;
private String bId;
private String model;
private String decay;
Getters and Setters
.....
When I remove the line aliasToBean and iterate over Object[] I could see the correct values fetched
Please guide me...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试显式为
ProjectionList
项添加别名以匹配 bean 中的字段名称,如下所示:Try explicitly aliasing the
ProjectionList
items to match the field names in the bean, as follows: