Ok the problem is so for Executefind () The return type was list....so there is no-to-use Uniqueresult () within the CA Llback from Executefind () ... May is we should use execute ()
The above words come from http://forum.springframework.org/showthread.php?t=58370
When using the Executefind method, an exception occurs if the data returned is not of the list type
Cases:
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 ());
}
The workaround is to change the Executefind method to the Execute method
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 ());
}
Result in Spring+hibernate object returned from Hibernatecallback isn ' t a List