使用Hibernate的 原生SQL 查询报错,求大神

hjw1197052444 2017-03-16 02:47:45
上代码:Example是我的实体类

String sql="select 1 ,2 from example";
SQLQuery q=sessionFactory.getCurrentSession().createSQLQuery(sql).addEntity("", Example.class);
return q.list();

如果我把sql改成:“ select 1,2 from dual ”; 就不会报错。
如果我 改成HQL 查询 也不会报错: Query q=sessionFactory.getCurrentSession().createQuery("from Example");也不会报错,
我就日了 狗了!

报错信息:

Struts Problem Report

Struts has detected an unhandled exception:

Messages:
Table 'mysql.example' doesn't exist
could not execute query
File: org/hibernate/exception/SQLStateConverter.java
Line number: 92
Stacktraces

org.hibernate.exception.SQLGrammarException: could not execute query
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
org.hibernate.loader.Loader.doList(Loader.java:2452)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2192)
org.hibernate.loader.Loader.list(Loader.java:2187)
org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1832)
org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:179)
cn.hjw.oa.dao.impl.ExamplDaoImpl.selAll(ExamplDaoImpl.java:63)
cn.hjw.oa.dao.impl.ExamplDaoImpl$$FastClassByCGLIB$$f9a596c5.invoke()
net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
cn.hjw.oa.dao.impl.ExamplDaoImpl$$EnhancerByCGLIB$$a921a677.selAll()
cn.hjw.oa.service.impl.ExampleServiceImpl.selAllService(ExampleServiceImpl.java:34)
cn.hjw.oa.action.ExampleAction.selAllAc(ExampleAction.java:39)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
...全文
273 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hjw1197052444 2017-03-20
  • 打赏
  • 举报
回复
我错了~谢谢 哥哥些
nikyotensai 2017-03-17
  • 打赏
  • 举报
回复
引用 3 楼 hjw1197052444 的回复:
Mysql中 就是全小写,而且 sql可以再 mysql 中运行。
你改成persons和pwd也不行吧
wrong1111 2017-03-17
  • 打赏
  • 举报
回复
Messages: Table 'mysql.example' doesn't exist could not execute query example确认在mysql库中么?
快跑蜗牛哥 2017-03-17
  • 打赏
  • 举报
回复
哥们,是不是连错资料库了??
超级菜鸟 2017-03-17
  • 打赏
  • 举报
回复
example不在mysql数据库下
hjw1197052444 2017-03-16
  • 打赏
  • 举报
回复
Mysql中 就是全小写,而且 sql可以再 mysql 中运行。
  • 打赏
  • 举报
回复
在mysql中大小写敏感吧,你试试把表名大小写对试一下看看
freekaiQaQ 2017-03-16
  • 打赏
  • 举报
回复
Messages: Table 'mysql.example' doesn't exist could not execute query 确认 表名 没错么,大小写什么的。

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧