hibernate createSQL how to cache it?

Posted by cometta on Stack Overflow See other posts from Stack Overflow or by cometta
Published on 2010-04-28T10:01:25Z Indexed on 2010/04/28 10:03 UTC
Read the original article Hit count: 291

Filed under:
|
|
|
|

If i use Criteria statement, i able to use cache easily. but when i using custom CREATESQL, like below, how do i cache it?

             Query query =  getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery(
                 " select  company_keysupplier.ddiv as ddiv, company_division.name as DIVISION, company_keysupplier.ddep as ddep,company_department.name as DEPARTMENT"+
                 " from company_keysupplier "+
                 " left join company_division on "+
                 " (company_keysupplier.ddiv= company_division.division_code and company_keysupplier.survey_num=company_division.survey_num) "+
                 " left join company_department on "+
                 " (company_keysupplier.ddep= company_department.department_code and company_keysupplier.survey_num=company_department.survey_num) "+
                 " where company_keysupplier.sdiv = :sdiv and company_keysupplier.sdep = :sdep and company_keysupplier.survey_num= :surveyNum  " +
                 " order by company_division.name, company_keysupplier.ddep " )


                 .addScalar("ddiv")
                 .addScalar("ddep")
                 .addScalar("DIVISION")
                 .addScalar("DEPARTMENT")


                   .setResultTransformer(Transformers.aliasToBean(IssKeysupplier.class));


                query.setString("sdiv", sdiv);
                query.setString("sdep", sdepartment);
                query.setBigInteger("surveyNum", survey_num);





//i tried  query.setCachable(true)  fail......

   List result= (List<IssKeysupplier>)query.list();


   return result;

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate