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>(MapperMethod.java:230 )
    at org.apache.ibatis.binding.MapperMethod. <init>(MapperMethod.java:48 )
    at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java: 65 )
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java: 58 )
    at com.sun.proxy.$Proxy18.deleteById(Unknown Source)
    at cn.xm.jwxt.ceshi.MpTest.test1(MpTest.java: 30 )
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 57 )
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 43 )
    at java.lang.reflect.Method.invoke(Method.java: 606 )
    at org.junit.runners.model.FrameworkMethod$ 1.runReflectiveCall(FrameworkMethod.java:44 )
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java: 15 )
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java: 41 )
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java: 20 )
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java: 75 )
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java: 86 )
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java: 84 )
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java: 263 )
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java: 254 )
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java: 89 )
    at org.junit.runners.ParentRunner$ 3.run(ParentRunner.java:231 )
    at org.junit.runners.ParentRunner$ 1.schedule(ParentRunner.java:60 )
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java: 229 )
    at org.junit.runners.ParentRunner.access$ 000(ParentRunner.java:50 )
    at org.junit.runners.ParentRunner$ 2.evaluate(ParentRunner.java:222 )
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java: 61 )
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java: 70 )
    at org.junit.runners.ParentRunner.run(ParentRunner.java: 292 )
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java: 193 )
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java: 86 )
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java: 38 )
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java: 459 )
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java: 675 )
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java: 382 )
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java: 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 *