当前位置: 首页 > Java > 正文

ibatis java.lang.NullPointerException分析

关键字:
1 星2 星3 星4 星5 星 (暂无评分)
Loading ... Loading ...
baidu_share

最近发现很奇怪的异常,在update时候报空指针错误。

java.lang.NullPointerException
        at com.**.InsertOrUpdateTask.call(InsertOrUpdateTask.java:69)
        at com.**.InsertOrUpdateTask.call(InsertOrUpdateTask.java:31)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
2014-09-09 15:25:24,045 ERROR - com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl[19] - InsertOrUpdateTask.

在代码位置显示,dao为空。在debug模式,dao不为空,发现报以下错误:

2014-09-09 17:04:13,815 ERROR - com.**.DataProcessDao[37] - [DataProcessDao][execute] 
org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0];   
--- The error occurred while applying a parameter map.  
--- Check the ProductBase.update-InlineParameterMap.  
--- Check the statement (update failed).  
--- Cause: com.mysql.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred while applying a parameter map.  
--- Check the ProductBase.update-InlineParameterMap.  
--- Check the statement (update failed).  
--- Cause: com.mysql.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
	at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:203)
	at com.**.DataProcessDao.execute(DataProcessDao.java:35)
	at org.springframework.orm.ibatis.SqlMapClientTemplate.update(SqlMapClientTemplate.java:378)
	at com.**.DataProcessDao.update(DataProcessDao.java:114)
	at com.**.dao.impl.LogicDaoImpl.update(LogicDaoImpl.java:56)
	at com.**.InsertOrUpdateTask.call(InsertOrUpdateTask.java:70)
	at com.**.task.InsertOrUpdateTask.call(InsertOrUpdateTask.java:31)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:662)
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred while applying a parameter map.  
--- Check the ProductBase.update-InlineParameterMap.  
--- Check the statement (update failed).  
--- Cause: com.mysql.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request
	at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:107)
	at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.update(SqlMapExecutorDelegate.java:457)
	at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.update(SqlMapSessionImpl.java:90)
	at org.springframework.orm.ibatis.SqlMapClientTemplate$9.doInSqlMapClient(SqlMapClientTemplate.java:380)
	at org.springframework.orm.ibatis.SqlMapClientTemplate$9.doInSqlMapClient(SqlMapClientTemplate.java:1)
	at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:200)
	... 11 more
Caused by: com.mysql.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2340)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2625)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119)
	at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1362)
	at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
	at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
	at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor.java:80)
	at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteUpdate(MappedStatement.java:216)
	at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:94)
	... 16 more

原来是由于更新字段过多(50个field),测试环境又是虚拟机,非常慢,导致超时,报空指针。
把defaultStatementTimeout=”6000″ 改大 问题依旧,看能真是虚拟机性能问题。

ibtais 打印sql日志配置:

	<appender name="IBatis" class="org.apache.log4j.ConsoleAppender">
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%-4r [%t] %-5p %c %x - %m%n" />
		</layout>
		<filter class="org.apache.log4j.varia.LevelRangeFilter">
			<param name="LevelMin" value="DEBUG" />
			<param name="LevelMax" value="DEBUG" />
		</filter>
	</appender>
 
	<logger name="com.ibatis" additivity="true">
		<level value="DEBUG" />
	</logger>
	<logger name="java.sql.Connection" additivity="true">
		<level value="DEBUG" />
	</logger>
	<logger name="java.sql.Statement" additivity="true">
		<level value="DEBUG" />
	</logger>
	<logger name="java.sql.PreparedStatement" additivity="true">
		<level value="DEBUG" />
		<appender-ref ref="IBatis" />
	</logger>
	<logger name="java.sql.ResultSet" additivity="true">
		<level value="DEBUG" />
		<appender-ref ref="IBatis" />
	</logger>

本文固定链接: http://www.chepoo.com/ibatis-java-lang-null-pointer-exception-analysis.html | IT技术精华网

ibatis java.lang.NullPointerException分析:等您坐沙发呢!

发表评论