mybatis-plus calls its own selectById method and reports an error: org.apache.ibatis.binding.BindingException:

The version number of mybatis-plus is 2.0.1, there is no error when calling its own insert(T), but an error is reported when executing update, and an error is also reported when calling selectById and deleteById. That is, errors are reported when the primary key is required to be identified.

The statement is as follows: (interface and implementation are implemented by MP itself)

        User selectById = userMapper1.selectById("ceshi" );
        userMapper1.deleteById( "ceshi");


The error message is as follows:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): cn.xm.jwxt.ceshi.mapper.UserMapper.deleteById
    at org.apache.ibatis.binding.MapperMethod$SqlCommand. <init>( )
    at org.apache.ibatis.binding.MapperMethod. <init>( )
    at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod( 65 )
    at org.apache.ibatis.binding.MapperProxy.invoke( 58 )
    at com.sun.proxy.$Proxy18.deleteById(Unknown Source)
    at cn.xm.jwxt.ceshi.MpTest.test1( 30 )
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke( 57 )
    at sun.reflect.DelegatingMethodAccessorImpl.invoke( 43 )
    at java.lang.reflect.Method.invoke( 606 )
    at org.junit.runners.model.FrameworkMethod$ 1.runReflectiveCall( )
    at 15 )
    at org.junit.runners.model.FrameworkMethod.invokeExplosively( 41 )
    at org.junit.internal.runners.statements.InvokeMethod.evaluate( 20 )
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate( 75 )
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate( 86 )
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate( 84 )
    at org.junit.runners.ParentRunner.runLeaf( 263 )
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild( 254 )
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild( 89 )
    at org.junit.runners.ParentRunner$ )
    at org.junit.runners.ParentRunner$ 1.schedule( )
    at org.junit.runners.ParentRunner.runChildren( 229 )
    at org.junit.runners.ParentRunner.access$ 000( )
    at org.junit.runners.ParentRunner$ 2.evaluate( )
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate( 61 )
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate( 70 )
    at 292 )
    at 193 )
    at 86 )
    at 38 )
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests( 459 )
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests( 675 )
    at 382 )
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( 192)


Reason: If it is a handwritten interface by yourself, you can find out the reason if you didn’t write SQL or the XML namespace of SQL was wrong, but this was implemented by MP itself, and the interface was not used.

After checking, in the entity class, if the @TableId(“database field name”) annotation is not added to the primary key field, this error occurs when calling the own method involving id. It is estimated that mybatis-plus cannot recognize the primary key field.


 Solution: Declare the name of the primary key column of the database.


Therefore, it is recommended that if you use Mybatis-Plus, it is best to annotate the table name (@TableName) and the table primary key (@TableId) in detail in the entity class to avoid such errors that are difficult to find the cause.
Another: It is said that the new version of mybatis-plus has solved this problem

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *