Home  >  Article  >  Database  >  atitit。hbHibernatesql查询使用

atitit。hbHibernatesql查询使用

WBOY
WBOYOriginal
2016-06-07 15:57:111060browse

atitit。 hb Hibernate sql 查询使用 #----------返回listmap法..这个推荐使用。 q.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); List li=q.list(); 作者 老哇的爪子 Attilax 艾龙, EMAIL:1466519819@qq.com 转载请注明来源: http://blog.csdn

atitit。 hb Hibernate sql 查询使用

#----------返回list法..这个推荐使用。
q.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
List li=q.list();


作者 老哇的爪子 Attilax 艾龙, EMAIL:1466519819@qq.com
转载请注明来源: http://blog.csdn.net/attilax

#------------------默认object[]法..
// attilax 老哇的爪子 下午04:57:03 2014-5-8
Session session = getSession();
Query q = session.createSQLQuery("SELECT TOP 1000 [id] ,[type] FROM [t_mb_activity] where type="+String.valueOf(actTypeId));
List li=q.list();
Object[] fields=(Object[]) li.get(0);
return (String) fields[0].toString();

#------List 默认好像就是这个。
q.setResultTransformer( Transformers.TO_LIST);
[[8, 2]]

#--注射bean
Transformers.aliasToBean(target) //把结果通过setter方法注入到指定的对像属性中


#-----返回单个的值
// 上午10:40:37 2014-4-29
// 检查该奖项是否还可以送
Session session = getSession();
String checkHql = "select count(*) as bingoNum from AwardWeixin where awardId!=null and openid=? and activityId="
+ actID;
Query cq = session.createQuery(checkHql);
cq.setParameter(0, uid);
// cq.list()
Long count = (Long) cq.uniqueResult();
// 该奖项还有余额

参考

Hibernate Transformers之三种结果转换说明 - seeareyoume的日志 - 网易博客.htm
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn