今天在调试myBatis调用Sybase数据库的存储过程的时候,出现了如下错误:
org.apache.ibatis.binding.BindingException: Mapper method 'getNextKey' (interface com.xxxxxxx.PackHandleMapper) attempted to return null from a method with a primitive return type (long).
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:37)
at $Proxy17.getNextKey(Unknown Source)
....
报错信息言下之意是返回值为空,可是我的存储过程明明是返回了一个记录集,存储过程如下:
- CREATE PROCEDURE prc_seq(@seq_name varchar(20))
- AS
- BEGIN
- UPDATE seq SET val=val+1 WHERE [name]=@seq_name
- SELECT val from seq WHERE [name]=@seq_name
- END
- GO
而且在数据库终端,可以成功执行和返回数据:
exec prc_seq 'xxx'
--------------------------------------------------------------------------------------------------------
经过排查得知,故障是由于update语句引起的,执行上面的语句,会产生两条执行记录,myBatis获取了update语句的执行情况:
1 record(s) affected
1 record(s) selected [Fetch MetaData: 0/ms] [Fetch Data: 0/ms]
解决方法,去掉update语句的执行情况返回,即增加语句:SET NOCOUNT ON
- CREATE PROCEDURE prc_seq(@seq_name varchar(20))
- AS
- BEGIN
- SET NOCOUNT ON
- UPDATE seq SET val=val+1 WHERE [name]=@seq_name
- SELECT val from seq WHERE [name]=@seq_name
- END
- GO
1F / 2012-09-16 09:21:35
! C:\Documents and Settings\Administrator\Local Settings\Temp\Rar$DI02.859\tencent-weibo-web-test.zip: 无法打开 C:\Documents and Settings\Administrator\Local Settings\Temp\Rar$DI02.859\tencent-weibo-web-test.zip
! 系统找不到指定的文件。