日期:2014-05-16  浏览次数:20735 次

使用Hibernate+MySql+native SQL的BUG,以及解决办法

?

使用Hibernate+MySql+native SQL的BUG,以及解决办法

?

转载自 http://blog.csdn.net/exsuns/article/details/5264125

?

本来是mssql+hibernate+native SQL 应用的很和谐

但是到了把mssql换成mysql,就出了错(同样的数据结构和数据)。

?

查询方法是:

[java] view plaincopy
  1. String?sql?=???
  2. "select?id?XXX_ID??from?t_tab";??
  3. List<Map>?list?=?session.createSQLQuery(sql)??
  4. .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)??
  5. .list();??

?


错误信息:

[css] view plaincopy
  1. org.hibernate.exception.SQLGrammarException:?could?not?execute?query??
  2. ????at?org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)??
  3. ????at?org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)??
  4. ????at?org.hibernate.loader.Loader.doList(Loader.java:2231)??
  5. ????at?org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)??
  6. ????at?org.hibernate.loader.Loader.list(Loader.java:2120)??
  7. ????at?org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:312)??
  8. ????at?org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1722)??
  9. ????at?org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)??
  10. ????at?org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:175)??
  11. ????at?com.exsun.common.dao.BasDaoImpl.findBySql(BasDaoImpl.java:173)??
  12. ????at?com.exsun.arms.service.EmployeesalaryService.getList(EmployeesalaryService.java:32)??
  13. ????at?com.exsun.arms.service.EmployeesalaryService$$FastClassByCGLIB$$2d81000f.invoke(<generated>)??
  14. ????at?net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)??
  15. ????at?org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)??
  16. ????at?org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)??
  17. ????at?org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)??
  18. ????at?org.springframework