在hibernate框架中使用sql语句

publicstaticList<Article>getArticleByArticleIds(StringarticleIds){

System.out.println("开始执行sql"+newDate());

Configurationcfg=newConfiguration().configure();

SessionFactorysf=cfg.buildSessionFactory();

Sessionsessions=sf.openSession();

List<Article>list=newArrayList<Article>();

Stringsql="selectid,title,summary,ori_publish_timeasoriPublishTime,gettime,keywords,"+

"_contentascontent,ori_addressasoriAddress,site_addressassiteAddress,cfg_workerascfgWorker,site_nameassiteNamefromt_articlewhereidin("+articleIds+")";

SQLQuerysqlQuery=sessions.createSQLQuery(sql);

sqlQuery.setResultTransformer(Transformers

.aliasToBean(Article.class));

List<Article>list1=sqlQuery.

addScalar("id",Hibernate.INTEGER).

addScalar("title",Hibernate.STRING).

addScalar("summary",Hibernate.STRING).

addScalar("oriPublishTime",Hibernate.TIMESTAMP).

addScalar("gettime",Hibernate.TIMESTAMP).

addScalar("keywords",Hibernate.STRING).

addScalar("content",Hibernate.STRING).

addScalar("oriAddress",Hibernate.STRING).

addScalar("cfgWorker",Hibernate.STRING).

addScalar("siteName",Hibernate.STRING).

list();

returnlist1;

}

相关推荐