有时候 我们会利用注解动态切换数据源,我们的数据类型一般会先通过 entity定义好。但 如果 我们查询的数据是 String 我们 entity里面是int或者double 则会导致匹配错误,从而导致数据源切换失败 错误代码如下:


2016-12-29 11:35:08 [ pool-1-thread-1:127528 ] - [ DEBUG ] Creating a new SqlSession 
2016-12-29 11:35:08 [ pool-1-thread-1:127528 ] - [ DEBUG ] Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@98e9e1d] 
2016-12-29 11:35:08 [ pool-1-thread-1:127528 ] - [ DEBUG ] Fetching JDBC Connection from DataSource 
2016-12-29 11:35:08 [ pool-1-thread-1:127528 ] - [ DEBUG ] Registering transaction synchronization for JDBC Connection 
2016-12-29 11:35:08 [ pool-1-thread-1:127528 ] - [ DEBUG ] JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@6297e5eb] will be managed by Spring 
2016-12-29 11:35:08 [ pool-1-thread-1:127528 ] - [ DEBUG ] ==>  Preparing: SELECT T1."ID" AS "ID", (CASE WHEN T1."STATUS" >=3 THEN 0 ELSE 1 END) AS "STATUS", T1."RESOURCE_TYPE", T1."EVENT_SUBMIT_TYPE", T1."ACIDENT_CAUSE" AS "ACCIDENT_CAUSE", T1."EVENT_RESPONSIBILITY", T1."RESOURCE_DATE", T1."EVENT_LEVEL", T3.IN_SCHOOL AS "LOCATION", T1."SUITABLE_DAMAGE", T1."EVENT_SCHOOL", T1."SCHOOL_TYPE", (CASE WHEN T1.INJURED_COUNT_MAN>0 OR T1.INJURED_COUNT_WOMAN>0 THEN 0 ELSE 1 END ) AS HAS_DEATH FROM TEENAGERS.EVENT T1, TEENAGERS.SYS_OFFICE T2, (SELECT T1.ID, T1.NAME AS NAME, T2.NAME AS IN_SCHOOL, T1.ROWID AS ID1, T2.ROWID AS ID2 FROM TEENAGERS.EVENT_LATITUDES T1, TEENAGERS.EVENT_LATITUDES T2 WHERE T1.PARENT_ID = T2.ID AND T2.TAG_NAME = 'location' ) T3 WHERE T1.EVENT_SCHOOL = T2.ID AND T1.LOCATION = T3.ID AND T2.GRADE = 3 AND T1.DEL_FLAG = '0' AND T1.CREATE_DATE <=?  
2016-12-29 11:35:08 [ pool-1-thread-1:127532 ] - [ DEBUG ] ==> Parameters: 2016-12-29 11:35:08.924(Timestamp) 
2016-12-29 11:35:08 [ pool-1-thread-1:127562 ] - [ DEBUG ] Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@98e9e1d] 
2016-12-29 11:35:08 [ pool-1-thread-1:127575 ] - [ DEBUG ] Adding [systemProperties] PropertySource with lowest search precedence 
2016-12-29 11:35:08 [ pool-1-thread-1:127575 ] - [ DEBUG ] Adding [systemEnvironment] PropertySource with lowest search precedence 
2016-12-29 11:35:08 [ pool-1-thread-1:127575 ] - [ DEBUG ] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment] 
2016-12-29 11:35:08 [ pool-1-thread-1:127576 ] - [ INFO ] Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml] 
2016-12-29 11:35:08 [ pool-1-thread-1:127577 ] - [ DEBUG ] Using JAXP provider [org.apache.xerces.jaxp.DocumentBuilderFactoryImpl] 
2016-12-29 11:35:08 [ pool-1-thread-1:127581 ] - [ DEBUG ] Found beans DTD [http://www.springframework.org/dtd/spring-beans-2.0.dtd] in classpath: spring-beans-2.0.dtd 
2016-12-29 11:35:08 [ pool-1-thread-1:127585 ] - [ DEBUG ] Loading bean definitions 
2016-12-29 11:35:09 [ pool-1-thread-1:127611 ] - [ DEBUG ] Creating shared instance of singleton bean 'DB2' 
2016-12-29 11:35:09 [ pool-1-thread-1:127611 ] - [ DEBUG ] Creating instance of bean 'DB2' 
2016-12-29 11:35:09 [ pool-1-thread-1:127611 ] - [ DEBUG ] Eagerly caching bean 'DB2' to allow for resolving potential circular references 
2016-12-29 11:35:09 [ pool-1-thread-1:127634 ] - [ DEBUG ] Finished creating instance of bean 'DB2' 
2016-12-29 11:35:09 [ pool-1-thread-1:127634 ] - [ DEBUG ] Creating shared instance of singleton bean 'Derby' 
2016-12-29 11:35:09 [ pool-1-thread-1:127634 ] - [ DEBUG ] Creating instance of bean 'Derby' 
2016-12-29 11:35:09 [ pool-1-thread-1:127634 ] - [ DEBUG ] Eagerly caching bean 'Derby' to allow for resolving potential circular references 
2016-12-29 11:35:09 [ pool-1-thread-1:127634 ] - [ DEBUG ] Finished creating instance of bean 'Derby' 
2016-12-29 11:35:09 [ pool-1-thread-1:127634 ] - [ DEBUG ] Creating shared instance of singleton bean 'H2' 
2016-12-29 11:35:09 [ pool-1-thread-1:127634 ] - [ DEBUG ] Creating instance of bean 'H2' 
2016-12-29 11:35:09 [ pool-1-thread-1:127634 ] - [ DEBUG ] Eagerly caching bean 'H2' to allow for resolving potential circular references 
2016-12-29 11:35:09 [ pool-1-thread-1:127634 ] - [ DEBUG ] Finished creating instance of bean 'H2' 
2016-12-29 11:35:09 [ pool-1-thread-1:127635 ] - [ DEBUG ] Creating shared instance of singleton bean 'HSQL' 
2016-12-29 11:35:09 [ pool-1-thread-1:127635 ] - [ DEBUG ] Creating instance of bean 'HSQL' 
2016-12-29 11:35:09 [ pool-1-thread-1:127635 ] - [ DEBUG ] Eagerly caching bean 'HSQL' to allow for resolving potential circular references 
2016-12-29 11:35:09 [ pool-1-thread-1:127635 ] - [ DEBUG ] Finished creating instance of bean 'HSQL' 
2016-12-29 11:35:09 [ pool-1-thread-1:127635 ] - [ DEBUG ] Creating shared instance of singleton bean 'Informix' 
2016-12-29 11:35:09 [ pool-1-thread-1:127635 ] - [ DEBUG ] Creating instance of bean 'Informix' 
2016-12-29 11:35:09 [ pool-1-thread-1:127635 ] - [ DEBUG ] Eagerly caching bean 'Informix' to allow for resolving potential circular references 
2016-12-29 11:35:09 [ pool-1-thread-1:127635 ] - [ DEBUG ] Finished creating instance of bean 'Informix' 
2016-12-29 11:35:09 [ pool-1-thread-1:127635 ] - [ DEBUG ] Creating shared instance of singleton bean 'MS-SQL' 
2016-12-29 11:35:09 [ pool-1-thread-1:127635 ] - [ DEBUG ] Creating instance of bean 'MS-SQL' 
2016-12-29 11:35:09 [ pool-1-thread-1:127635 ] - [ DEBUG ] Eagerly caching bean 'MS-SQL' to allow for resolving potential circular references 
2016-12-29 11:35:09 [ pool-1-thread-1:127635 ] - [ DEBUG ] Finished creating instance of bean 'MS-SQL' 
2016-12-29 11:35:09 [ pool-1-thread-1:127635 ] - [ DEBUG ] Creating shared instance of singleton bean 'MySQL' 
2016-12-29 11:35:09 [ pool-1-thread-1:127644 ] - [ DEBUG ] Creating instance of bean 'MySQL' 
2016-12-29 11:35:09 [ pool-1-thread-1:127644 ] - [ DEBUG ] Eagerly caching bean 'MySQL' to allow for resolving potential circular references 
2016-12-29 11:35:09 [ pool-1-thread-1:127645 ] - [ DEBUG ] Finished creating instance of bean 'MySQL' 
2016-12-29 11:35:09 [ pool-1-thread-1:127645 ] - [ DEBUG ] Creating shared instance of singleton bean 'Oracle' 
2016-12-29 11:35:09 [ pool-1-thread-1:127645 ] - [ DEBUG ] Creating instance of bean 'Oracle' 
2016-12-29 11:35:09 [ pool-1-thread-1:127645 ] - [ DEBUG ] Eagerly caching bean 'Oracle' to allow for resolving potential circular references 
2016-12-29 11:35:09 [ pool-1-thread-1:127645 ] - [ DEBUG ] Finished creating instance of bean 'Oracle' 
2016-12-29 11:35:09 [ pool-1-thread-1:127645 ] - [ DEBUG ] Creating shared instance of singleton bean 'PostgreSQL' 
2016-12-29 11:35:09 [ pool-1-thread-1:127645 ] - [ DEBUG ] Creating instance of bean 'PostgreSQL' 
2016-12-29 11:35:09 [ pool-1-thread-1:127645 ] - [ DEBUG ] Eagerly caching bean 'PostgreSQL' to allow for resolving potential circular references 
2016-12-29 11:35:09 [ pool-1-thread-1:127646 ] - [ DEBUG ] Finished creating instance of bean 'PostgreSQL' 
2016-12-29 11:35:09 [ pool-1-thread-1:127646 ] - [ DEBUG ] Creating shared instance of singleton bean 'Sybase' 
2016-12-29 11:35:09 [ pool-1-thread-1:127646 ] - [ DEBUG ] Creating instance of bean 'Sybase' 
2016-12-29 11:35:09 [ pool-1-thread-1:127646 ] - [ DEBUG ] Eagerly caching bean 'Sybase' to allow for resolving potential circular references 
2016-12-29 11:35:09 [ pool-1-thread-1:127646 ] - [ DEBUG ] Finished creating instance of bean 'Sybase' 
2016-12-29 11:35:09 [ pool-1-thread-1:127646 ] - [ INFO ] SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase] 
2016-12-29 11:35:09 [ pool-1-thread-1:127646 ] - [ DEBUG ] Looking up default SQLErrorCodes for DataSource [com.jt.report.util.db.DynamicDataSource@7a3d90de] 
2016-12-29 11:35:09 [ pool-1-thread-1:127654 ] - [ DEBUG ] Database product name cached for DataSource [com.jt.report.util.db.DynamicDataSource@7a3d90de]: name is 'Oracle' 
2016-12-29 11:35:09 [ pool-1-thread-1:127655 ] - [ DEBUG ] SQL error codes for 'Oracle' found 
2016-12-29 11:35:09 [ pool-1-thread-1:127655 ] - [ DEBUG ] Unable to translate SQLException with Error code '17059', will now try the fallback translator 
2016-12-29 11:35:09 [ pool-1-thread-1:127656 ] - [ DEBUG ] Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@98e9e1d] 
2016-12-29 11:35:09 [ pool-1-thread-1:127656 ] - [ DEBUG ] Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@98e9e1d] 
2016-12-29 11:35:09 [ pool-1-thread-1:127656 ] - [ DEBUG ] Returning JDBC Connection to DataSource 
2016-12-29 11:35:09 [ pool-1-thread-1:127656 ] - [ DEBUG ] Should roll back transaction but cannot - no transaction available 
2016-12-29 11:35:09 [ pool-1-thread-1:127664 ] - [ ERROR ] slaveEventForInsert 
java.lang.reflect.InvocationTargetException 
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
	at java.lang.reflect.Method.invoke(Unknown Source) 
	at com.jt.report.scheduler.ReportJob.DynamicJobMethod(ReportJob.java:100) 
	at com.jt.report.scheduler.ReportJob.exeForInsert(ReportJob.java:47) 
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
	at java.lang.reflect.Method.invoke(Unknown Source) 
	at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) 
	at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) 
	at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81) 
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) 
	at java.util.concurrent.FutureTask.run(Unknown Source) 
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source) 
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) 
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
	at java.lang.Thread.run(Unknown Source) 
Caused by: org.springframework.jdbc.UncategorizedSQLException: Error attempting to get column 'RESOURCE_TYPE' from result set.  Cause: java.sql.SQLException: 无法转换为内部表示 
; uncategorized SQLException for SQL []; SQL state [null]; error code [17059]; 无法转换为内部表示; nested exception is java.sql.SQLException: 无法转换为内部表示 
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84) 
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) 
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) 
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:74) 
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399) 
	at com.sun.proxy.$Proxy12.selectList(Unknown Source) 
	at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:205) 
	at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:122) 
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:64) 
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53) 
	at com.sun.proxy.$Proxy47.getSlaveEvent(Unknown Source) 
	at com.jt.report.service.impl.SlaveDbServiceImpl.getSlaveEvent(SlaveDbServiceImpl.java:90) 
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
	at java.lang.reflect.Method.invoke(Unknown Source) 
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) 
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) 
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) 
	at com.alibaba.druid.support.spring.stat.DruidStatInterceptor.invoke(DruidStatInterceptor.java:72) 
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98) 
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262) 
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95) 
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
	at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:52) 
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52) 
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) 
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) 
	at com.sun.proxy.$Proxy48.getSlaveEvent(Unknown Source) 
	at com.jt.report.scheduler.BusinessJob.slaveEventForInsert(BusinessJob.java:292) 
	... 20 more 
Caused by: java.sql.SQLException: 无法转换为内部表示 
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) 
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146) 
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208) 
	at oracle.jdbc.driver.CharCommonAccessor.getBigDecimal(CharCommonAccessor.java:341) 
	at oracle.jdbc.driver.OracleResultSetImpl.getBigDecimal(OracleResultSetImpl.java:1549) 
	at oracle.jdbc.driver.OracleResultSet.getBigDecimal(OracleResultSet.java:2042) 
	at com.alibaba.druid.filter.FilterChainImpl.resultSet_getBigDecimal(FilterChainImpl.java:1049) 
	at com.alibaba.druid.filter.FilterAdapter.resultSet_getBigDecimal(FilterAdapter.java:1462) 
	at com.alibaba.druid.filter.FilterChainImpl.resultSet_getBigDecimal(FilterChainImpl.java:1047) 
	at com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl.getBigDecimal(ResultSetProxyImpl.java:245) 
	at com.alibaba.druid.pool.DruidPooledResultSet.getBigDecimal(DruidPooledResultSet.java:493) 
	at sun.reflect.GeneratedMethodAccessor45.invoke(Unknown Source) 
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
	at java.lang.reflect.Method.invoke(Unknown Source) 
	at org.apache.ibatis.logging.jdbc.ResultSetLogger.invoke(ResultSetLogger.java:68) 
	at com.sun.proxy.$Proxy67.getBigDecimal(Unknown Source) 
	at org.apache.ibatis.type.BigDecimalTypeHandler.getNullableResult(BigDecimalTypeHandler.java:38) 
	at org.apache.ibatis.type.BigDecimalTypeHandler.getNullableResult(BigDecimalTypeHandler.java:27) 
	at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:66) 
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getPropertyMappingValue(DefaultResultSetHandler.java:411) 
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyPropertyMappings(DefaultResultSetHandler.java:384) 
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:346) 
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:298) 
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:273) 
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:246) 
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:160) 
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:63) 
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:78) 
	at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) 
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:303) 
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:154) 
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:102) 
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82) 
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:120) 
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:113) 
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
	at java.lang.reflect.Method.invoke(Unknown Source) 
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:386) 
	... 49 more 
2016-12-29 11:35:09 [ pool-1-thread-1:127666 ] - [ DEBUG ] Creating a new SqlSession 
2016-12-29 11:35:09 [ pool-1-thread-1:127666 ] - [ DEBUG ] SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@45ecf975] was not registered for synchronization because synchronization is not active 
2016-12-29 11:35:09 [ pool-1-thread-1:127666 ] - [ DEBUG ] Fetching JDBC Connection from DataSource 
2016-12-29 11:35:09 [ pool-1-thread-1:127666 ] - [ DEBUG ] JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@6297e5eb] will not be managed by Spring 
2016-12-29 11:35:09 [ pool-1-thread-1:127666 ] - [ DEBUG ] ==>  Preparing: select job_id, job_name, start_time, end_time, job_status from SYNC_JOB where start_time = (select max (start_time) from sync_job where rownum = 1 and job_name = ? ) and job_name = ?  
2016-12-29 11:35:09 [ pool-1-thread-1:127667 ] - [ DEBUG ] ==> Parameters: slaveEventPersonForInsert(String), slaveEventPersonForInsert(String) 
2016-12-29 11:35:09 [ pool-1-thread-1:127692 ] - [ DEBUG ] Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@45ecf975] 
2016-12-29 11:35:09 [ pool-1-thread-1:127692 ] - [ DEBUG ] Returning JDBC Connection to DataSource 
2016-12-29 11:35:09 [ pool-1-thread-1:127692 ] - [ DEBUG ] Looking up default SQLErrorCodes for DataSource [com.jt.report.util.db.DynamicDataSource@7a3d90de] 
2016-12-29 11:35:09 [ pool-1-thread-1:127692 ] - [ DEBUG ] SQLErrorCodes found in cache for DataSource [com.jt.report.util.db.DynamicDataSource@7a3d90de] 
2016-12-29 11:35:09 [ pool-1-thread-1:127692 ] - [ DEBUG ] Translating SQLException with SQL state '42000', error code '942', message [ORA-00942: 表或视图不存在 
]; SQL was [] for task [ 
### Error querying database.  Cause: java.sql.SQLException: ORA-00942: 表或视图不存在 
 
### The error may exist in file [F:\06_Study\Workspaces\Eclipse64ForJwaq\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\teenagers-report\WEB-INF\classes\com\jt\report\mapper\SyncJobMapper.xml] 
### The error may involve com.jt.report.mapper.SyncJobMapper.selectByJob-Inline 
### The error occurred while setting parameters 
### SQL: select              job_id, job_name, start_time, end_time, job_status         from SYNC_JOB     where start_time = (select max (start_time) from sync_job where  rownum = 1             and job_name = ?                 )             and job_name = ? 
### Cause: java.sql.SQLException: ORA-00942: 表或视图不存在 
 
] 
2016-12-29 11:35:09 [ pool-1-thread-1:127694 ] - [ ERROR ] slaveEventPersonForInsert 
org.springframework.jdbc.BadSqlGrammarException:  
### Error querying database.  Cause: java.sql.SQLException: ORA-00942: 表或视图不存在 
 
### The error may exist in file [F:\06_Study\Workspaces\Eclipse64ForJwaq\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\teenagers-report\WEB-INF\classes\com\jt\report\mapper\SyncJobMapper.xml] 
### The error may involve com.jt.report.mapper.SyncJobMapper.selectByJob-Inline 
### The error occurred while setting parameters 
### SQL: select              job_id, job_name, start_time, end_time, job_status         from SYNC_JOB     where start_time = (select max (start_time) from sync_job where  rownum = 1             and job_name = ?                 )             and job_name = ? 
### Cause: java.sql.SQLException: ORA-00942: 表或视图不存在 
 
; bad SQL grammar []; nested exception is java.sql.SQLException: ORA-00942: 表或视图不存在 
 
	at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231) 
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) 
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:74) 
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399) 
	at com.sun.proxy.$Proxy12.selectOne(Unknown Source) 
	at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:165) 
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:69) 
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53) 
	at com.sun.proxy.$Proxy53.selectByJob(Unknown Source) 
	at com.jt.report.service.impl.SyncJobServiceImpl.selectByJob(SyncJobServiceImpl.java:58) 
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
	at java.lang.reflect.Method.invoke(Unknown Source) 
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) 
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) 
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) 
	at com.alibaba.druid.support.spring.stat.DruidStatInterceptor.invoke(DruidStatInterceptor.java:72) 
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98) 
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262) 
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95) 
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
	at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:52) 
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52) 
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) 
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) 
	at com.sun.proxy.$Proxy54.selectByJob(Unknown Source) 
	at com.jt.report.scheduler.ReportJob.startsyncJobForUpdate(ReportJob.java:195) 
	at com.jt.report.scheduler.ReportJob.startsyncJob(ReportJob.java:126) 
	at com.jt.report.scheduler.ReportJob.DynamicJobMethod(ReportJob.java:93) 
	at com.jt.report.scheduler.ReportJob.exeForInsert(ReportJob.java:49) 
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
	at java.lang.reflect.Method.invoke(Unknown Source) 
	at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) 
	at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) 
	at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81) 
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) 
	at java.util.concurrent.FutureTask.run(Unknown Source) 
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source) 
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) 
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
	at java.lang.Thread.run(Unknown Source) 
Caused by: java.sql.SQLException: ORA-00942: 表或视图不存在

解决方式: 对下一个操作,强制进行却换


@DataSource(name=DataSource.dataSourceMaster)
  SyncJob selectByJob(SyncJob syncJob);


数据源利用AOP注解 却换代码:


    public void before(Method method, Object[] args, Object target)   
            throws Throwable {   
    	//这里DataSource是自定义的注解,不是java里的DataSource接口 
        if (method.isAnnotationPresent(DataSource.class))    
        {   
            DataSource datasource = method.getAnnotation(DataSource.class); 
            if(null == datasource || (null != datasource && null == datasource.name())) 
            	DataSourceContextHolder.setDataSource(datasource.dataSourceMaster); 
    		else { 
    			System.out.println(datasource.name()); 
    			DataSourceContextHolder.setDataSource(datasource.name());   
    		} 
        }   
           
    }




评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!