首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

HQL简略多属性查询 构建新对象

2012-07-25 
HQL简单多属性查询 构建新对象public List GetTop5NewsTitle(String type) {// TODO Auto-generated metho

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         ... ...}

热点排行