关于hibernate查询,数据库字段为clob的错误原因及解决方法记录

时间:2021-09-07 07:38:02

关于hibernate查询,数据库字段为clob的错误原因及解决方法记录

关于hibernate查询,数据库字段为clob的错误原因及解决方法记录

数据库content字段为clob类型,下图为实体类

关于hibernate查询,数据库字段为clob的错误原因及解决方法记录

当采取hibernate查询时会报出

Hibernate: select mobileexch0_.ID as ID199_, mobileexch0_.CONTENT as CONTENT199_, mobileexch0_.MOBILE_EXCHANGE_ITEM_ID as MOBILE3_199_, mobileexch0_.MOBILE_FORUM_SECTION_TYPE_ID as MOBILE4_199_, mobileexch0_.MOBILE_FORUM_SECTION_TYPE_NAME as MOBILE5_199_, mobileexch0_.SCORE as SCORE199_, mobileexch0_.TIME as TIME199_, mobileexch0_.USER_ID as USER8_199_, mobileexch0_.USER_NAME as USER9_199_ from MOBILE_EXCHANGE_ITEME_REVIEW mobileexch0_ where 1=1 and mobileexch0_.MOBILE_EXCHANGE_ITEM_ID='4028808557dcd7710157dcec02f60004'
2016-10-19 22:39:35.632 [http-8080-Processor21]  ERROR org.hibernate.util.JDBCExceptionReporter[101] - Conversion to String failed
2016-10-19 22:39:35.642 [http-8080-Processor21]  ERROR org.apache.struts2.dispatcher.DefaultDispatcherErrorHandler[42] - Exception occurred during processing request: could not read next row of results
org.hibernate.exception.GenericJDBCException: could not read next row of results
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
at org.hibernate.loader.Loader.loadSingleRow(Loader.java:303) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
at org.hibernate.impl.ScrollableResultsImpl.prepareCurrentRow(ScrollableResultsImpl.java:254) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
at org.hibernate.impl.ScrollableResultsImpl.last(ScrollableResultsImpl.java:105) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
at com.ultrapower.eoms.common.core.dao.HibernateDaoImpl.pagedQuery(HibernateDaoImpl.java:454) [HibernateDaoImpl.class:na]
at com.ultrapower.eoms.common.core.dao.HibernateDaoImpl.pagedQuery(HibernateDaoImpl.java:423) [HibernateDaoImpl.class:na]
at com.ultrapower.eoms.common.core.dao.HibernateDaoImpl$$FastClassByCGLIB$$6bff8d9e.invoke(<generated>) [cglib-nodep-2.2.jar:na]
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191) [cglib-nodep-2.2.jar:na]
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700) [spring-2.5.6.jar:2.5.6]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) [spring-2.5.6.jar:2.5.6]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106) [spring-2.5.6.jar:2.5.6]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) [spring-2.5.6.jar:2.5.6]
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635) [spring-2.5.6.jar:2.5.6]
at com.ultrapower.eoms.common.core.dao.HibernateDaoImpl$$EnhancerByCGLIB$$4ed31cad.pagedQuery(<generated>) [cglib-nodep-2.2.jar:na]
at com.ultrapower.mams.mobileForum.service.impl.MobileExchangeItemServiceImpl.pageListMobileExchangeItemeReview(MobileExchangeItemServiceImpl.java:123) [MobileExchangeItemServiceImpl.class:na]
at com.ultrapower.mams.mobileForum.web.MobileForumAction.mobileExchangeItemeReviewFrame(MobileForumAction.java:248) [MobileForumAction.class:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [na:1.5.0_17]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [na:1.5.0_17]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [na:1.5.0_17]
at java.lang.reflect.Method.invoke(Method.java:585) [na:1.5.0_17]
at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:871) [ognl-3.0.14.jar:na]
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1294) [ognl-3.0.14.jar:na]
at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68) [ognl-3.0.14.jar:na]
at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:117) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:108) [xwork-core-2.3.28.1.jar:2.3.28.1]
at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1370) [ognl-3.0.14.jar:na]
at ognl.ASTMethod.getValueBody(ASTMethod.java:90) [ognl-3.0.14.jar:na]
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212) [ognl-3.0.14.jar:na]
at ognl.SimpleNode.getValue(SimpleNode.java:258) [ognl-3.0.14.jar:na]
at ognl.Ognl.getValue(Ognl.java:494) [ognl-3.0.14.jar:na]
at ognl.Ognl.getValue(Ognl.java:458) [ognl-3.0.14.jar:na]
at com.opensymphony.xwork2.ognl.OgnlUtil$2.execute(OgnlUtil.java:315) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecute(OgnlUtil.java:346) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.ognl.OgnlUtil.getValue(OgnlUtil.java:313) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:430) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:290) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:251) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) [xwork-core-2.3.28.1.jar:2.3.28.1]
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91) [struts2-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) [xwork-core-2.3.28.1.jar:2.3.28.1]
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:253) [struts2-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:140) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) [xwork-core-2.3.28.1.jar:2.3.28.1]
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) [struts2-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193) [xwork-core-2.3.28.1.jar:2.3.28.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245) [xwork-core-2.3.28.1.jar:2.3.28.1]
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) [struts2-core-2.3.28.1.jar:2.3.28.1]
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:567) [struts2-core-2.3.28.1.jar:2.3.28.1]
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81) [struts2-core-2.3.28.1.jar:2.3.28.1]
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99) [struts2-core-2.3.28.1.jar:2.3.28.1]
at com.ultrapower.mams.mobileForum.filter.UeditorFilter.doFilter(UeditorFilter.java:28) [UeditorFilter.class:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) [catalina.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) [catalina.jar:na]
at com.ultrapower.eoms.common.core.web.SessionFilter.doFilter(SessionFilter.java:40) [SessionFilter.class:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) [catalina.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) [catalina.jar:na]
at com.ultrapower.eoms.common.core.web.WebActionContextFilter.doFilter(WebActionContextFilter.java:187) [WebActionContextFilter.class:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) [catalina.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) [catalina.jar:na]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96) [spring-2.5.6.jar:2.5.6]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-2.5.6.jar:2.5.6]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) [catalina.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) [catalina.jar:na]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) [catalina.jar:na]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) [catalina.jar:na]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) [catalina.jar:na]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) [catalina.jar:na]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) [catalina.jar:na]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) [catalina.jar:na]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) [tomcat-http.jar:na]
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) [tomcat-http.jar:na]
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) [tomcat-util.jar:5.1]
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) [tomcat-util.jar:5.1]
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) [tomcat-util.jar:5.1]
at java.lang.Thread.run(Thread.java:595) [na:1.5.0_17]
Caused by: java.sql.SQLException: Conversion to String failed
at oracle.sql.Datum.stringValue(Datum.java:181) [ojdbc14_g.jar:Oracle JDBC Driver version - "10.2.0.1.0"]
at oracle.jdbc.driver.ScrollableResultSet.getString(ScrollableResultSet.java:777) [ojdbc14_g.jar:Oracle JDBC Driver version - "10.2.0.1.0"]
at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1515) [ojdbc14_g.jar:Oracle JDBC Driver version - "10.2.0.1.0"]
at org.hibernate.type.StringType.get(StringType.java:41) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:184) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:173) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:105) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2124) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1404) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1332) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
at org.hibernate.loader.Loader.getRow(Loader.java:1230) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:603) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
at org.hibernate.loader.Loader.loadSingleRow(Loader.java:291) [hibernate-core-3.3.1.GA.jar:3.3.1.GA]
... 86 common frames omitted

解决办法:将实体类对应content字段加上注解:@Type(type = "text")

如下图

关于hibernate查询,数据库字段为clob的错误原因及解决方法记录

即可解决问题。