随笔-3  评论-2  文章-0  trackbacks-0
请高手教教我吧.
在hibernate中查询数据,查询语句中包含sql函数String sql = (select * from employee emp where left(dbo.f_GetPy(name,1)='要查询的字母')
其中dbo.f_GetPy(name),1)为sql server 2000中的自定义函数,"name"是列名。其作用是按汉字的字符串的第一个字的英文首字母查出相应的字符串(按首字母查询)。
我用的是List list = session.createSQLQuery(sql)
.addEntity("emp",Employee.class)
.list() ;
方法。
报的错误是.list()那行。sql语句在查询分析器中试过了,没问题。具体错误代码如下:

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: could not execute query
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
yfy.struts.MyActionServlet.process(MyActionServlet.java:17)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

org.hibernate.exception.SQLGrammarException: could not execute query
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
org.hibernate.loader.Loader.doList(Loader.java:2148)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
org.hibernate.loader.Loader.list(Loader.java:2024)
org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:111)
org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1655)
org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:164)
yfy.dao.BaseDaoImpl.execSQLQuery(BaseDaoImpl.java:138)
yfy.struts.action.EmpNameListAction.execute(EmpNameListAction.java:40)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
yfy.struts.MyActionServlet.process(MyActionServlet.java:17)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

请高手们帮我解答。谢谢
posted on 2008-09-23 19:01 想想 阅读(594) 评论(2)  编辑  收藏

评论:
# re: 帮帮我,hibernate的sql查询出错??? 2008-10-03 16:08 | roywang
String sql = (select * from employee emp where left(dbo.f_GetPy(name,1)='要查询的字母')
我觉得这里有问题,在Hibernate中语法应该是 from 类名 where 属性名
是面向对象的,而不是用表格的列名  回复  更多评论
  
# re: 帮帮我,hibernate的sql查询出错??? [未登录] 2010-05-24 16:11 | 111
@roywang
人家要用的是sql查询!!!  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: