日期:2014-05-20  浏览次数:21527 次

org.springframework.orm.hibernate3.HibernateQueryException: Expected positional
[code=Java][/code]public Page<Product> findByName(String where, final Object obj, final int pageNo, final int pageSize) {
final StringBuilder sb = new StringBuilder("FROM Product p WHERE 1=1");
if (where != null && !"".equals(where.trim())) {
sb.append(" AND ");
sb.append(where);
}
Page<Product> page = new Page<Product>(pageNo, pageSize);
page.setResult((List<Product>)getHibernateTemplate().executeFind(new HibernateCallback() {

@Override
public Object doInHibernate(Session session) throws HibernateException,
SQLException {
return session.createQuery(sb.toString()).setFirstResult((pageNo-1)*pageSize).setMaxResults(pageSize).list();
}
}));
return page;
}

异常信息:

org.springframework.orm.hibernate3.HibernateQueryException: Expected positional parameter count: 1, actual parameters: [] [FROM Product p WHERE 1=1 AND p.name LIKE ?]; nested exception is org.hibernate.QueryException: Expected positional parameter count: 1, actual parameters: [] [FROM Product p WHERE 1=1 AND p.name LIKE ?]
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:657)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:343)
com.lqkj.dao.impl.ProductDaoImpl.findByName(ProductDaoImpl.java:85)
com.lqkj.service.impl.ProductServiceImpl.findByName(ProductServiceImpl.java:58)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
$Proxy7.findByName(Unknown Source)
com.lqkj.web.ProductAction.query(ProductAction.java:105)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)