4
回答
HibernateDaoSupport 执行SQL 报错
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

就这样一条sql,在Navicat中能够正常执行。但是通过Hibernate查询就报错,说“NAME”列不存在!!

List<Object[]> obj = this.getQcyOrderInfoDAO().executeSQLQuery("
SELECT smw.ID AS smwID,smw.`NAME` AS '窗口', 
CASE   WHEN smsi.`WEEK`=1 then '星期一' 
WHEN smsi.`WEEK`=2 then '星期二'   
WHEN smsi.`WEEK`=3 then '星期三'  
WHEN smsi.`WEEK`=4 then '星期四'  
WHEN smsi.`WEEK`=5 then '星期五' 
WHEN smsi.`WEEK`=6 then '星期六'  
WHEN smsi.`WEEK`=7 then '星期日'  
END as '星期',   
smms3.ID, smms3.`NAME` '主餐别', 
sms.id  AS  smsID,   sms.`NAME`  AS '次餐别',  sms.SEQUENCE  AS smsSequence,   
smat.`NAME`  AS '属性' , smat.ID AS smatID , sm.`NAME`  AS '菜名'   
from smart_menu_schedule_item AS smsi   
LEFT JOIN smart_menu as sm ON sm.ID = smsi.SMART_MENU_ID   
LEFT JOIN smart_menu_attribute smat on smat.ID =  smsi.MENU_ATTRIBUTE_ID  
LEFT JOIN smart_menu_meal_sort sms on sms.id = smsi.SORT_ID   
LEFT JOIN smart_menu_window smw on smw.ID = smsi.WINDOW_ID  
LEFT JOIN smart_menu_meal_sort as smms2  ON sms.id= smms2.ID  
LEFT JOIN smart_menu_meal_sort as smms3  ON  smms3.ID=smms2.HEADER_ID  
where smsi.HEADER_ID = 261 ");

dao层的代码:

/**
 * <b>基础DAO支持</b><br/>
 * <b>说明:</b>所有的DAO层类,都要继承这个DAO
 * 
 */
@Repository
public class CommonDAO extends HibernateDaoSupport {
	private Session session() {
		return getSession();
	}
 	public SQLQuery createSQLQuery(final String sql) {
		return this.session().createSQLQuery(sql);
	} 
}
错误信息:
WARN - [org.hibernate.util.JDBCExceptionReporter:line 77]SQL Error: 0, SQLState: S0022
ERROR - [org.hibernate.util.JDBCExceptionReporter:line 78]Column 'NAME' not found.
ERROR - [com.hestia.mosa.qcy.controller.QcyOrderInfoController:line 109]could not execute query
ERROR - [com.hestia.mosa.qcy.controller.QcyOrderInfoController:line 116]org.hibernate.exception.SQLGrammarException: could not execute query
程序中有不通过Hibernate执行sql的地方,就不会报这个错误。

请高手指点啊,感谢啦……


举报
pengcheng_1024
发帖于4年前 4回/588阅

以下是问题补充:

  • @pengcheng_1024 :怎么就这么多人浏览每人回答啊!!都别打酱油啊……,留点足迹吧 (4年前)
  • @pengcheng_1024 :我实际想问的是为什么一条可以执行的sql通过Hibernate去查询就报这个错误啊?? (4年前)
顶部