简单的HibernatealiasToBean

简单的HibernatealiasToBean

本文介绍了简单的HibernatealiasToBean()无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码对我不起作用:

The following code isn't working for me:

List results = getSession().createCriteria(User.class)
    .setProjection(Projections.projectionList()
            .add(Projections.property("userName"))
    )
    .setResultTransformer(Transformers.aliasToBean(UserSummary.class))
    .list();


有趣的是,如果删除setResultTransformer(),我会得到一个很好的返回用户名列表.


Funny enough though if I remove the setResultTransformer() I get a list of userNames returned back perfectly fine.

这是我的UserSummary类:

Here is my UserSummary class:

public class UserSummary {

    private String userName;
    private String clickUrl;
    private Integer id;

    public UserSummary() {}

    public UserSummary(Integer id, String userName) {
        this.id = id;
        this.userName = userName;
        this.clickUrl = clickUrl;
    }

    public String getUserName() {
        return userName;
    }

    public String getClickUrl() {
        return clickUrl;
    }

    public void setClickUrl(String clickUrl) {
        this.clickUrl = clickUrl;
    }

    public Integer getId() {
        return id;
    }
}


有想法吗?


Thoughts?

推荐答案

已修复.

必须更改我的投影,所以看起来像这样.

Had to change my projection so it looked like this..

.add(Projections.property("userName"), "userName")

很奇怪..但是我猜是可行的.

Odd.. but whatever works I guess.

这篇关于简单的HibernatealiasToBean()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 17:20