spring+hibernate中的Result object returned from HibernateCallback isn't a List
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方法時(shí),如果返回的不是List類型的數(shù)據(jù)則會(huì)出現(xiàn)引異常
例:
?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());
?}
總結(jié)
以上是生活随笔為你收集整理的spring+hibernate中的Result object returned from HibernateCallback isn't a List的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DNS服务器未响应指的是什么意思
- 下一篇: 登录token无效的解决方法