熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

Hibernate3的DetachedCriteria支持[3]

2022-06-13   來源: Java開源技術 

  解決方法禁止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)));
}

[]  []  []  


From:http://tw.wingwit.com/Article/program/Java/ky/201311/29140.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.