hql select new 应用

最近有很多朋友用到select new 方法。下面我给大家举个简单的例子。

定义类:

public class TycoonRow implements Serializable {

    private static final long serialVersionUID = -8902581963250812345L;

    private int id;

    private String name;

    public TycoonRow(int id, String name) {
        super();
        this.id = id;
        this.checkNo = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

 

    public int getName() {
        return name;
    }

    public void setName(int name) {
        this.name= name;
    }


执行sql语句。

select new cn.dbdh.new.TycoonRow(tb1.id as id,ch.tb2 as name) "
                            + "from table_1 tb1,table_2 tb2 where tb1.id=tb2.id

说明:hql语句中的列名必须和实体类中的变量一一对应并且名称相同,顺序相同。希望对需要的朋友给与帮助

posted @ 2012-12-19 16:36  东北大亨  阅读(1348)  评论(0编辑  收藏  举报