解决方法禁止Spring的HibernateTemplate传递Proxy类强制要求它传递真实的SessionImpl类即给exexute方法增加一个参数提供参数为true如下
java代码
public List findByCriteria(final DetachedCriteria detachedCriteria) {
return (List) getHibernateTemplate()execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
Criteria criteria = detachedCriteriagetExecutableCriteria(session);
return criterialist();
}
} true);
}
附一个进行模糊查询的例子
public PaginationSupport findPageByCriteria(int startIndex int pageSize String sortColumnId Boolean bSortOrder final String likeValue) {
DetachedCriteria detachedCriteria = DetachedCriteria forClass(Timeclass);
// like condition
if ((likeValue != null && likeValuetrim()length() > )) {
detachedCriteriaadd(Restrictionsor(RestrictionssqlRestriction(statime like ? % + likeValue + % HibernateSTRING)RestrictionssqlRestriction(endtime like ? % + likeValue + % HibernateSTRING)));
}
[] [] []