?
使用Hibernate+MySql+native SQL的BUG,以及解决办法
?
转载自 http://blog.csdn.net/exsuns/article/details/5264125
?
本来是mssql+hibernate+native SQL 应用的很和谐
但是到了把mssql换成mysql,就出了错(同样的数据结构和数据)。
?
查询方法是:
- String?sql?=???
- "select?id?XXX_ID??from?t_tab";??
- List<Map>?list?=?session.createSQLQuery(sql)??
- .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)??
- .list();??
?
错误信息:
- org.hibernate.exception.SQLGrammarException:?could?not?execute?query??
- ????at?org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)??
- ????at?org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)??
- ????at?org.hibernate.loader.Loader.doList(Loader.java:2231)??
- ????at?org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)??
- ????at?org.hibernate.loader.Loader.list(Loader.java:2120)??
- ????at?org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:312)??
- ????at?org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1722)??
- ????at?org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)??
- ????at?org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:175)??
- ????at?com.exsun.common.dao.BasDaoImpl.findBySql(BasDaoImpl.java:173)??
- ????at?com.exsun.arms.service.EmployeesalaryService.getList(EmployeesalaryService.java:32)??
- ????at?com.exsun.arms.service.EmployeesalaryService$$FastClassByCGLIB$$2d81000f.invoke(<generated>)??
- ????at?net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)??
- ????at?org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)??
- ????at?org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)??
- ????at?org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)??
- ????at?org.springframework