首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

不轨范的代价

2012-09-17 
不规范的代价@Transactional(readOnlytrue)@SuppressWarnings(unchecked)public ListBranch getChild

不规范的代价

@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 +"'" ;

热点排行