1. 程式人生 > >Hibernate使用SQL查詢返回實體型別

Hibernate使用SQL查詢返回實體型別

注意實體類資料名稱要和查詢欄位名稱一樣

String sql = null;

sql="select a.tagid,a.datetime,a.value,b.tagname,b.danwei,b.image,b.standvalue from Station"+station+" a left join tagDesc b on a.tagid=b.tagid where a.tagid="+tagid+" and a.datetime =(select MAX(datetime) from Station"+station+" where tagid="+tagid+")";

List<Export> list =this.getSession().createSQLQuery(sql).setResultTransformer(Transformers.aliasToBean(Export.class)).list()