spring+hibernate中的Result object returned from HibernateCallback isn't a List
来源:互联网 发布:sql语句按降序排列 编辑:程序博客网 时间:2024/04/30 11:02
Ok the problem is that for executeFind() the return type is List....so there is no way to use uniqueResult() within the callback from executeFind()...may be we should use execute()
上面这段话来自http://forum.springframework.org/showthread.php?t=58370
在使用executeFind方法时,如果返回的不是List类型的数据则会出现引异常
例:
public Integer findCount(final Class clazz,final String str) {
return Integer.parseInt(getHibernateTemplate().executeFind(new HibernateCallback()
{
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
StringBuilder sb=new StringBuilder();
sb.append("select count(*) from ");
sb.append(clazz.getName());
sb.append(" ");
sb.append(str);
log.info(sb.toString());
return session.createQuery(sb.toString()).uniqueResult();
}
}).toString());
}
解决方法是把executeFind方法改为execute方法
public Integer findCount(final Class clazz,final String str) {
return Integer.parseInt(getHibernateTemplate().execute(new HibernateCallback()
{
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
StringBuilder sb=new StringBuilder();
sb.append("select count(*) from ");
sb.append(clazz.getName());
sb.append(" ");
sb.append(str);
log.info(sb.toString());
return session.createQuery(sb.toString()).uniqueResult();
}
}).toString());
}
有问题?直接google!<script type="text/javascript"><!-- google_ad_client = "pub-0757178726455256"; google_ad_format = "js_sdo"; google_cts_mode ="rs"; google_num_cts = "2"; google_searchbox_width = 215; google_searchbox_height = 26; google_link_target = 2; google_logo_pos = "left"; google_rs_pos = "right"; google_ad_height = 35; google_ad_width = 760;// --></script><script src="http://pagead2.googlesyndication.com/pagead/show_sdo.js" type="text/javascript"></script>
<script type="text/javascript"><!--google_ad_client = "pub-0757178726455256";/* 728x90, 创建于 09-6-17 */google_ad_slot = "1633515232";google_ad_width = 728;google_ad_height = 90;// --></script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>
- spring+hibernate中的Result object returned from HibernateCallback isn't a List
- 关于Hibernate中的HibernateCallback
- It isn't possible to write into a document from an asynchronously-loaded
- When a QThread isn't a thread...
- warning: function declaration isn't a prototype
- function declaration isn't a prototype 是什么原因
- warning: function declaration isn't a prototype
- function declaration isn't a prototype解决办法
- function declaration isn't a prototype
- storage size of 'a' isn't known
- warning: function declaration isn't a prototype
- error: function declaration isn’t a prototype
- function declaration isn't a prototype解决办法
- Weex This isn't a hierarchical URI.
- java.lang.IllegalArgumentException: Object returned from onCreateLoader must not be a non-static inn
- java.lang.IllegalArgumentException: Object returned from onCreateLoader must not be a non-static inn
- Error result 31 returned from 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\mt.exe
- error PRJ0002 : Error result 31 returned from 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\mt.
- maven入门-http://zhouyaoh.javaeye.com/blog/56961
- WinCE嵌入式开发程序入门
- 2009.02.11
- 小视不得!WinImage打造超强启动盘
- 勇敢面对人生,真诚对待自己
- spring+hibernate中的Result object returned from HibernateCallback isn't a List
- NO_DATA_FOUND
- 动画流程的思考
- TOMCAT IOException while loading persisted sessions: java.io.EOFException
- Quizfarm
- 发现一款强大的自动采集软件myspider
- 重构并非设计的替代品
- maven入门2
- 暴笑笑话集