Hirbernate 的二级缓存不受控 可能引发的问题

query.setCacheable(true);

使用查询缓存 可能第一次没取到数据就无法缓存 认定该语句无返回结果 即使你把语句丢到

数据库工具中能查到数据 该方法也返回的结果也是没有数据

 public List<Object> getSyllabusByNowTime(String date) {
  StringBuilder sql = new StringBuilder();
  sql.append("SELECT s.*,b.class_name className,c.subject_name subjectName,d.teacher_name teacherName,e.syllabustype_Name syllabustypeName ");
  sql.append("FROM TBL_DRM_SYLLABUS s,TBL_DRM_CLASS b,TBL_DRM_SUBJECT c,TBL_DRM_TEACHER d,DATA_DRM_SYLLABUSTYPE e ");
  sql.append("where s.TEACHER_ID = d.TEACHER_ID ");
  sql.append("and s.subject_Id = c.subject_Id ");
  sql.append("and s.class_Id = b.class_Id ");
  sql.append("and s.syllabus_Type = e.syllabustype_Id ");
  sql.append("and s.DEL_FLG = 0 and b.DEL_FLG = 0  ");
  sql.append("and s.SYLLABUS_DATE = '");
  sql.append(date+" 00:00:00.000' ");
  sql.append("and datediff(hour,getdate(),CAST(SUBSTRING(CONVERT(varchar, s.SYLLABUS_DATE, 120 ),0,11)+' '+SUBSTRING(s.CLASS_PERIOD,0,6) as datetime))<10 ");
  sql.append(" order by s.SYLLABUS_DATE desc");
  Query query = getSession().createSQLQuery(sql.toString());
  //query.setCacheable(true);
  System.out.println(sql.toString());
  List<Object> objs = query.list();
  return objs;
 }