不规范的代价
@Transactional(readOnly=true)@SuppressWarnings("unchecked")public List<Branch> getChildrenByCateId(String cateId){String hql = "from Branch b where b.parentId = " + cateId ;Query query = branchDaoImpl.createQuery(hql);return query.getResultList();}当CATEID为008 009 或是 08 09 时 或是 8 9结尾的字符串时 不得取得query
捣鼓一个多小时 不知哪原因 想想没有其它差异 为什么当是 8 9结尾时就出错
最终发现是自己不规范呀 cateId是字符串类型的
故而HQL语句应如下
String hql = "from Branch b where b.parentId = '" + cateId +"'" ;