HQL简单多属性查询 构建新对象
public List GetTop5NewsTitle(String type) {// TODO Auto-generated method stubSession session=HibernateSessionFactory.getSession();Query query=session.createQuery("select new TNews(id,title,type) from TNews t where t.type=:ttype order by t.createtime desc").setString("ttype", type);query.setFirstResult(1);query.setMaxResults(5);List list=query.list();session.close();return list;}package com.baitw.hibernate.entity;import java.util.Date;/** * TNews entity. @author MyEclipse Persistence Tools */public class TNews implements java.io.Serializable {// Fieldsprivate Long id;private String title;private Integer type;private String content;private Date createtime;private Long operid;private Integer state;// Constructors/** default constructor */public TNews() {}/** minimal constructor */public TNews(Long id, String title, Integer type) {this.id = id;this.title = title;this.type = type;}/** full constructor */public TNews(Long id, String title, Integer type, String content,Date createtime, Long operid, Integer state) {this.id = id;this.title = title;this.type = type;this.content = content;this.createtime = createtime;this.operid = operid;this.state = state;}// Property accessors ... ...}