my batis 에서 CTE 를 사용 하여 Oacle 조회 데이터 형식 이 long 인 필드 에서 스 트림 종료 문 제 를 해결 합 니 다.

오늘 notice 표 의 content 필드 를 log 필드 로 바 꾼 후 이 필드 를 포함 한 CTE 를 사용 하 는 검색 어 를 잘못 보 고 했 습 니 다.오 류 를 알려 주세요.
 
### Cause: java.sql.SQLException:      
; uncategorized SQLException for SQL []; SQL state [99999]; error code [17027];      ; nested exception is java.sql.SQLException:      ] with root cause
java.sql.SQLException:      
	at oracle.jdbc.driver.LongAccessor.getBytesInternal(LongAccessor.java:156)
	at oracle.jdbc.driver.LongAccessor.getBytes(LongAccessor.java:126)
	at oracle.jdbc.driver.LongAccessor.getString(LongAccessor.java:201)
	at oracle.jdbc.driver.T4CLongAccessor.getString(T4CLongAccessor.java:427)
	at oracle.jdbc.driver.OracleResultSetImpl.getString(OracleResultSetImpl.java:1251)
	at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:494)
	at sun.reflect.GeneratedMethodAccessor30.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.apache.ibatis.logging.jdbc.ResultSetLogger.invoke(ResultSetLogger.java:67)
	at com.sun.proxy.$Proxy75.getString(Unknown Source)
	at org.apache.ibatis.type.StringTypeHandler.getNullableResult(StringTypeHandler.java:37)
	at org.apache.ibatis.type.StringTypeHandler.getNullableResult(StringTypeHandler.java:26)
	at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:55)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getPropertyMappingValue(DefaultResultSetHandler.java:390)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyPropertyMappings(DefaultResultSetHandler.java:364)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:338)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:291)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:266)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:236)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:150)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:60)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:73)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)
	at com.moral.frame.dao.PaginationInterceptor.query(PaginationInterceptor.java:137)
	at com.moral.frame.dao.PaginationInterceptor.intercept(PaginationInterceptor.java:78)
	at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:60)
	at com.sun.proxy.$Proxy140.query(Unknown Source)
	at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:60)
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
	at com.sun.proxy.$Proxy83.selectList(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:205)
	at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:117)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
	at com.sun.proxy.$Proxy122.getReceiveNoticeList(Unknown Source)
	at com.moral.notice.service.impl.NoticeServiceImpl.getReceiveNoticeList(NoticeServiceImpl.java:161)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
	at com.sun.proxy.$Proxy126.getReceiveNoticeList(Unknown Source)
	at com.moral.notice.view.NoticeController.getNoticeListPage(NoticeController.java:69)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)

         그러나 저 는 CTE 검색 어 를 사용 하지 않 았 습 니 다. 정상적으로 실행 할 수 있 고 오류 가 발생 하지 않 습 니 다. 다음은 cte 검색 어 와 일반적인 검색 어 입 니 다.
 
 
	    With NoticeCTE As(
			Select 
				*
			from (
				Select
					noticeKey,
					title,
					content
				From Notice
				Order by noticeKey desc	
			)
		), NoticeReadCTE As(
			Select 
			    distinct nc.noticeKey, 1 readState 
			From NoticeCTE nc, notice_Reader nr
			Where nc.noticeKey = nr.noticeKey
			And nr.readerCode = #{readerCode}
		)
		Select
			nc.*, readState
		From NoticeCTE nc
		left join NoticeReadCTE rc on nc.noticeKey = rc.noticeKey 
		order by nc.noticeKey desc 
	

         다음은 일반적인 검색 어 입 니 다.
 
 
		Select
			noticeKey,
			title,
			content
		From Notice
		Where noticeKey = #{noticeKey}


      log 형식 을 clob 로 바 꾸 면 상기 sql 문 구 는 정상적으로 실 행 될 수 있 습 니 다.이 같은 이유 가 생 긴 것 은:
 
      1. cte 는 자동 으로 임시 표를 만 듭 니 다.
      2. long 형식 필드 를 포함 하여 create table b as select * from a 방식 으로 표를 만 들 수 없습니다.
    3. 동시에 long 데이터 형식 은 시간 이 지 났 습 니 다. 사용 을 권장 하지 않 습 니 다. clob 데이터 형식 을 사용 하 는 것 을 권장 합 니 다.
    또한 맵 전달 파 라미 터 를 사용 하여 mybaits 의 CTE 검색 어 에 전달 할 때 반드시 파 라미 터 를 지정 한 데이터 형식 을 명 확 히 해 야 하 며 그렇지 않 으 면 다음 과 같은 오 류 를 보고 할 수 있 음 을 발견 하 였 다
 
; uncategorized SQLException for SQL []; SQL state [99999]; error code [17004];       : 1111; nested exception is java.sql.SQLException:       : 1111] with root cause
java.sql.SQLException:       : 1111
	at oracle.jdbc.driver.OracleStatement.getInternalType(OracleStatement.java:3900)
	at oracle.jdbc.driver.OraclePreparedStatement.setNullCritical(OraclePreparedStatement.java:4406)
	at oracle.jdbc.driver.OraclePreparedStatement.setNull(OraclePreparedStatement.java:4388)
	at oracle.jdbc.driver.OraclePreparedStatementWrapper.setNull(OraclePreparedStatementWrapper.java:1281)
	at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:43)
	at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:81)
	at com.moral.frame.dao.PaginationInterceptor.setParameters(PaginationInterceptor.java:210)
	at com.moral.frame.dao.PaginationInterceptor.count(PaginationInterceptor.java:166)
	at com.moral.frame.dao.PaginationInterceptor.query(PaginationInterceptor.java:135)
	at com.moral.frame.dao.PaginationInterceptor.intercept(PaginationInterceptor.java:78)
	at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:60)
	at com.sun.proxy.$Proxy72.query(Unknown Source)
	at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:60)
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
	at com.sun.proxy.$Proxy14.selectList(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:205)
	at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:117)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
	at com.sun.proxy.$Proxy54.getReceiveNoticeList(Unknown Source)
	at com.moral.notice.service.impl.NoticeServiceImpl.getReceiveNoticeList(NoticeServiceImpl.java:162)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
	at com.sun.proxy.$Proxy58.getReceiveNoticeList(Unknown Source)
	at com.moral.notice.view.NoticeController.getNoticeListPage(NoticeController.java:80)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)

      올 바른 my baitis 의 sql 문 구 를 설정 합 니 다.
 
 
	    With NoticeCTE As(
			Select 
				*
			from (
				Select
					noticeKey,
					title,
					content
				From Notice
				
				  
				      
				      	 and divisionKey in (
				      	     
				      	     #{divisionKey, jdbcType=VARCHAR}
				      	 
				      	 )
				      
				      
				      
			                  And createCode != #{readerCode, jdbcType=VARCHAR}
				      				      		      
				  
				
				Order by noticeKey desc	
			)
			
			  
			      
			          and rowNum <= #{noticeCount, jdbcType=NUMBERIC}
			      
			  
			
		), NoticeReadCTE As(
			Select 
			    distinct nc.noticeKey, 1 readState 
			From NoticeCTE nc, mor_notice_Reader nr
			Where nc.noticeKey = nr.noticeKey
		        And nr.readerCode = #{readerCode, jdbcType=VARCHAR}
		)
		Select
			nc.*, readState
		From NoticeCTE nc
		left join NoticeReadCTE rc on nc.noticeKey = rc.noticeKey 
		order by nc.noticeKey desc 

       오류 가 발생 한 이 유 는 들 어 오 는 매개 변 수 는 Map 형식 이 고 my batis 는 매개 변수의 실제 유형 을 확정 할 수 없 기 때문에 수 동 으로 지정 해 야 합 니 다.
 
다음으로 전송:https://www.cnblogs.com/wala-wo/p/5119188.html

좋은 웹페이지 즐겨찾기