解決方法禁止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 = detachedCriteria
getExecutableCriteria(session);
return criteria
list();
}
}
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)));
}
[] [] []
From:http://tw.wingwit.com/Article/program/Java/ky/201311/29140.html