org.hibernate.exception.GenericJDBCException: could not execute query

分类: 错误分析 |
Exception in thread "main"
org.hibernate.exception.GenericJDBCException: could not execute
query
at
org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
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.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
at
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
at
org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
at
com.hxht.wj.common.orm.HibernateDao.query(HibernateDao.java:102)
at
com.hxht.wj.common.orm.HibernateDao.getAll(HibernateDao.java:94)
at
com.hxht.wj.service.NvmpUserManager.getAllUser(NvmpUserManager.java:20)
at
com.hxht.wj.service.NvmpUserManager$$FastClassByCGLIB$$a5be8628.invoke()
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.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
at
com.hxht.wj.service.NvmpUserManager$$EnhancerByCGLIB$$5d71be54.getAllUser()
at
com.hxht.wj.test.Test.test(Test.java:40)
at
com.hxht.wj.test.Test.main(Test.java:25)
Caused by: java.sql.SQLException: Invalid value for getLong() - '2bac8d4e2dae4bb6817d7198b353f97a'
at
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at
com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:2919)
at
com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:2830)
at
com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:2942)
at
com.mchange.v2.c3p0.impl.NewProxyResultSet.getLong(NewProxyResultSet.java:2625)
at
org.hibernate.type.LongType.get(LongType.java:51)
at
org.hibernate.type.NullableType.nullSafeGet(NullableType.java:184)
at
org.hibernate.type.NullableType.nullSafeGet(NullableType.java:173)
at
org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:126)
at
org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2124)
at
org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1404)
at
org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1332)
at
org.hibernate.loader.Loader.getRow(Loader.java:1230)
at
org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:603)
at
org.hibernate.loader.Loader.doQuery(Loader.java:724)
at
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at
org.hibernate.loader.Loader.doList(Loader.java:2228)
... 18
more
-------------------------------------------------
使用SSH全注解的方式做hibernate映射时,遇到上面这个问题。两个表的映射关系如下,Check表对User表,一对多关系。
Check实体类字段如下:
http://s1/mw690/700dec94gd9d0b2c2cf70&690couldnot execute query" TITLE="org.hibernate.exception.GenericJDBCException: could not execute query" />
User实体类关键字段如下:
http://s4/mw690/700dec94gd9d0bd383a03&690couldnot execute query" TITLE="org.hibernate.exception.GenericJDBCException: could not execute query" />
Caused by: java.sql.SQLException: Invalid value for getLong() - '2bac8d4e2dae4bb6817d7198b353f97a'
这行错误信息是说,hibernate中映射的字段类型不匹配。想想这是为什么呢?原来我的两个表做映射的时候,Check表中的CheckUserId是外键,关联的不是User表中的主键Id字段,而是UserId字段,Id是Long类型,UserId是字符串类型,所以,hibernate把Check表的CheckUserId字段映射到User类中的Id字段上了,所以出了类型不匹配的错误,解决办法就是讲@Id注解手动写到userId上去,叫userId标注为主键。(真是蛋疼!)
Caused by: java.sql.SQLException: Invalid value for getLong() - '2bac8d4e2dae4bb6817d7198
-------------------------------------------------
使用SSH全注解的方式做hibernate映射时,遇到上面这个问题。两个表的映射关系如下,Check表对User表,一对多关系。
Check实体类字段如下:
http://s1/mw690/700dec94gd9d0b2c2cf70&690could
User实体类关键字段如下:
http://s4/mw690/700dec94gd9d0bd383a03&690could
Caused by: java.sql.SQLException: Invalid value for getLong() - '2bac8d4e2dae4bb6817d7198
这行错误信息是说,hibernate中映射的字段类型不匹配。想想这是为什么呢?原来我的两个表做映射的时候,Check表中的CheckUserId是外键,关联的不是User表中的主键Id字段,而是UserId字段,Id是Long类型,UserId是字符串类型,所以,hibernate把Check表的CheckUserId字段映射到User类中的Id字段上了,所以出了类型不匹配的错误,解决办法就是讲@Id注解手动写到userId上去,叫userId标注为主键。(真是蛋疼!)