3

I extended a MyBatis Mapper in order to take advantage of Java 8 lambda functions like this:

public interface MyTableMapper extends IBatchInsertUpdateMapper<MyTable> {...}
public interface IBatchInsertUpdateMapper<T> extends IBatchInsertMapper<T>, IBatchUpdateMapper<T> {}
public interface IBatchInsertMapper<T> { public int insert(T record); }
public interface IBatchUpdateMapper<T> { public int updateByPrimaryKey(T record); }

Interestingly, when I run the code under Tomcat7, the Eclipsed compiled code runs fine, but with Maven compiled code, I get:

java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.xxx.mybatis.mapper.MyTableMapper.selectByPrimaryKey
     at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:660)
     at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:495)
     at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:488)
     at org.apache.ibatis.binding.MapperMethod.setupCommandType(MapperMethod.java:236)
     at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:71)
     at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:39)
     at com.sun.proxy.$Proxy52.selectByPrimaryKey(Unknown Source)
     ...

It seems that ibatis can find the insert() and updateByPrimaryKey() methods but can't find other methods in the MyTableMapper interface.

Any idea why?

FYI, I'm using:

  • jdk1.8.0_66
  • build-helper-maven-plugin: 1.7
  • maven-enforcer-plugin: 1.3.1

Maven is compiling with 1.8.0_66:

Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T17:37:52+00:00)
Maven home: C:\Users\Me\workspaceLunaSr2\Dev\EMBEDDED
Java version: 1.8.0_66, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_66\jre
Default locale: en_GB, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"

Similarly, Eclipse is reporting that I'm using 1.8.0_66:

java.endorsed.dirs=C:\Program Files\Java\jre1.8.0_66\lib\endorsed
java.ext.dirs=C:\Program Files\Java\jre1.8.0_66\lib\ext;C:\Windows\Sun\Java\lib\ext
java.home=C:\Program Files\Java\jre1.8.0_66

In case you're wondering, the reason behind all this is because I found MyBatis batch insert using

<foreach>...</foreach>

very inefficient. A much more efficient way was presented here: MyBatis Batch Insert/Update For Oracle, and with the help of lambda functions, I only need to write one method to do batch insert/update/etc.

Community
  • 1
  • 1
RayCh
  • 571
  • 3
  • 8
  • 17

0 Answers0