HibernateTemplate 페이지 조회

2041 단어 DAOHibernate
이 종 류 는 hibenate 맵 에서 자동 으로 생 성 되 는 DAO 클래스 입 니 다.
public class TCompanyDAO extends HibernateDaoSupport {
    private static final Log log = LogFactory.getLog(TCompanyDAO.class);
    //(1)     
       private static HibernateTemplate hibernateTemplate =new HibernateTemplate (HibernateSessionFactory.getSessionFactory());


 

//(2) 

    protected void initDao() {
        // do nothing       
    }

 

 

 public static List getCompanyListForPage(final int offset, final int lengh) {     
        log.debug("finding getCompanyListForPage    ");
        try {
            List list = hibernateTemplate.executeFind(new HibernateCallback(){                
                String queryString = "from TCompany";
                public Object doInHibernate(Session session)
                        throws HibernateException, SQLException {                    
                    List list2 = session.createQuery(queryString)
                            .setFirstResult(offset)
                            .setMaxResults(lengh)
                            .list(); 
                    return list2;
                }});
            
            return list;
        } catch (RuntimeException re) {
            
            log.error("find ListForPage failed", re);
            throw re;
        }
    }

 

}

이상 의 코드 는 프로그램 이 실 행 될 때 제3자 소프트웨어 로 데 이 터 를 삽입 할 때 이 방법 으로 최신 데 이 터 를 얻 을 수 없습니다.
해결 방법 은 다음 과 같다.
나 는 두 곳 의 수정 을 할 것 이다.
위의 빨 간 글 자 를 보 세 요.
(1) //     
    private static HibernateTemplate hibernateTemplate;

 

(2)    protected void initDao() {
        // do nothing      

        hibernateTemplate=getHibernateTemplate();//        HibernateDaoSupport    
    }

좋은 웹페이지 즐겨찾기