日期:2014-05-17  浏览次数:20752 次

求助---mybatis注解问题
Exception in thread "main" org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error selecting key or setting result to parameter object. Cause: org.apache.ibatis.reflection.ReflectionException: Could not set property 'USER_ID' of 'com.lc.model.Users@1638fff7' with value 'null' Cause: java.lang.IllegalArgumentException
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:346)
at $Proxy9.insert(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:231)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:59)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:38)
at $Proxy13.insert(Unknown Source)
at com.lc.dao.UsersDao.insert(UsersDao.java:52)
at com.lc.main.Main.main(Main.java:27)

--------------这个是我的添加方法,我想要返回添加后的自增值.添加方法没问题.-------------------
--------------Users这个是我的entity别名. @Alias("Users")--------------------------
@Insert("INSERT INTO Web.dbo.EB_BASE_USER VALUES(#{Users.NICK_NAME},#{Users.LOGIN_ID},#{Users.USER_PWD},#{Users.LOGIN_EMAIL},#{Users.LOGIN_PHONE},#{Users.STATUS})")
@SelectKey(before = false, keyProperty = "Users.USER_ID", resultType = int.class, statement = { "SELECT IDENT_CURRENT('EB_BASE_USER') as USER_ID" })
public abstract int insert(@Param("Users") Users user);

------------------------求解--------------------------------------




------解决方案--------------------
数据库里USER_ID的类型是不是数值型?
插入null这个文字列的话,会出这个错的
------解决方案--------------------
你先以mybatis的datasource中的用户和密码链接数据库,执行SELECT IDENT_CURRENT('EB_BASE_USER') as USER_ID,看结果。
------解决方案--------------------
说句不太中听的话,MyBatis用Annotation有点歪了。
------解决方案--------------------
Insert语句要加上ID字段