我觉的应该是Hibernate解析的问题吧,因为如果我把HQL改成: String childHQL = "select model.name,select count(m) from TmibItem m where m.name like concat('com','.%') and m.termModel.id=1,model.id "; childHQL = childHQL+" from TmibItem as model where model.name like 'com.%' "; childHQL = childHQL+" and model.termModel.id=1"; childHQL = childHQL+" and instr(substring(model.name,5),'.')=0"; Hibernate会把它解析成SQL: select count(tmibitem0_.ID) as x0_0_ from t_mib_item tmibitem0_, t_mib_item tmibitem1_ where (tmibitem0_.ITEM_NAME like concat('com' , '.%'))and(tmibitem0_.TERM_MODEL_ID=1 , model.id(tmibitem1_.ITEM_NAME like 'com.%' )and(tmibitem1_.TERM_MODEL_ID=1 )and(instr(substring(tmibitem1_.ITEM_NAME , 5), '.')=0 ) 显然这是一条错误的语句 也许HQL真的没达到那么强大吧
String childHQL = "select model.name,select count(m) from TmibItem m where m.name like concat('com','.%') and m.termModel.id=1,model.id ";
childHQL = childHQL+" from TmibItem as model where model.name like 'com.%' ";
childHQL = childHQL+" and model.termModel.id=1";
childHQL = childHQL+" and instr(substring(model.name,5),'.')=0";
Hibernate会把它解析成SQL: select count(tmibitem0_.ID) as x0_0_ from t_mib_item tmibitem0_, t_mib_item tmibitem1_ where (tmibitem0_.ITEM_NAME like concat('com' , '.%'))and(tmibitem0_.TERM_MODEL_ID=1 , model.id(tmibitem1_.ITEM_NAME like 'com.%' )and(tmibitem1_.TERM_MODEL_ID=1 )and(instr(substring(tmibitem1_.ITEM_NAME , 5), '.')=0 )
显然这是一条错误的语句
也许HQL真的没达到那么强大吧