Tag Archives: invalid bound statement (not found)

[Solved] Springboot Project mybatis Error: Invalid bound statement (not found)

There are many reasons for mybatis to report an error: Invalid bound statement (not found), but just like the error message, the sql statement in the xml cannot be found. There are three types of errors:

Type 1: Syntax error

Java DAO layer interface

public  void delete(@Param("id")String id);

Java corresponding mapper.xml file

<? xml version="1.0" encoding="UTF-8" ?> 
<! DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis -3-mapper.dtd" > 
< mapper namespace ="xxx.xxx.xxx.Mapper" > 
    <!-- delete data --> 
    < delete id ="delete" parameterType ="java.lang.String" >
        DELETE FROM xxx WHERE id=#{id}
    </ delete > 
</ mapper >

Check: 1. Whether the method name (delete) in the interface is consistent with the id=”delete” in the xml file

2. Whether the path in namespace=”xxx.xxx.xxx.Mapper” in the xml file is consistent with the path of the interface file

3. Whether parameterType and resultType are accurate; resultMap and resultType are different.

Second: compile error

Navigate to the project path: under the error path in target\classes\, find out whether the corresponding xml file exists.

(1) If there is no corresponding xml file, you need to add the following code to pom.xml:

< build > 
    < resources > 
         < resource > 
             < directory > src/main/java </ directory > 
             < excludes > 
                 < exclude > **/*.java </ exclude > 
             </ excludes > 
         </ resource > 
         < resource > 
             < directory > src/main/resources </ directory > 
             < includes > 
                 < include >**/*.* </include > 
             </ includes > 
        </ resource > 
    </ resources > 
</ build >

Delete the files in the classes folder, recompile, and the corresponding xml file appears.

(2) If there is an xml file, open the xml file and check whether the error part is consistent with the source file and inconsistent, then

First clear the files in the classes folder, execute the command: mvn clean to clean up the content, and then recompile.

The third type: configuration error

There was a problem with the configuration path when specifying scan packages in the project configuration file. For example: the specification of the “basePackage” property package name in the spring configuration file must be specific to the package where the interface is located, and do not write the parent or even higher-level package, otherwise problems may occur; cn.dao and cn.* may also cause errors ; Note that when scanning, the package may not be scanned.

Fourth: Referenced dependency package error

The project has always been running normally. When I recompiled the project one day, I found that this error has been reported all the time. I checked it again according to the previous three methods, and the error is still reported. Finally, I suddenly remembered that the company released a message a few days ago, saying that there are several internal dependency packages updated, because I wrote [xxx,) in the pom.xml file, and the latest dependency package will be automatically referenced. Then I modified the pom.xml file, returned the version to the old version, and after recompiling, the problem was solved.

[Solved] mybatis Multi-Module Error: Invalid bound statement (not found)

2022-01-07 14:43:03.030 ERROR 18120 --- [schedule-pool-1] com.inkyi.system.service.SysLogService   : Invalid bound statement (not found): com.inkyi.system.mapper.SysOperLogMapper.insertSelective

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.inkyi.system.mapper.SysOperLogMapper.insertSelective
	at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235) ~[mybatis-3.5.9.jar:3.5.9]
	at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53) ~[mybatis-3.5.9.jar:3.5.9]
	at org.apache.ibatis.binding.MapperProxy.lambda$cachedInvoker$0(MapperProxy.java:108) ~[mybatis-3.5.9.jar:3.5.9]
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705) ~[na:na]
	at org.apache.ibatis.util.MapUtil.computeIfAbsent(MapUtil.java:35) ~[mybatis-3.5.9.jar:3.5.9]
	at org.apache.ibatis.binding.MapperProxy.cachedInvoker(MapperProxy.java:95) ~[mybatis-3.5.9.jar:3.5.9]
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:86) ~[mybatis-3.5.9.jar:3.5.9]
	at com.sun.proxy.$Proxy81.insertSelective(Unknown Source) ~[na:na]
	at com.inkyi.system.service.SysLogService.insertOperlog(SysLogService.java:21) ~[main/:na]
	at com.inkyi.framework.manager.AsyncFactory$1.run(AsyncFactory.java:88) ~[main/:na]
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na]
	at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264) ~[na:na]
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java) ~[na:na]
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
	at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]

The project modules are as follows:

Mapper.XML and mapper classes are 100% sure.

That’s the configuration problem. Check to scan mapper in the configuration file XML configuration

#mybatis
mybatis.type-aliases-package=com.inkyi.*.entity
mybatis.mapper-locations=classpath:mapper/*/*.xml

Set

mybatis. mapper-locations=classpath:mapper/*/*. xml

Change to

mybatis. mapper-locations=classpath*:mapper/*/*. xml

Classpath: only the class directory under this project will be scanned

Classpath *: class directory in jar package will be scanned

After introducing mybatisplus, the user-defined method is used to solve the invalid bound statement (not found) error

I tried all the methods on the Internet, but they didn’t work.

Finally, I took a look at the. YML configuration file,

mybatis-plus:
  mapper-locations: classpath:mappers/*Mapper.xml
  type-aliases-package: com.xxxxx.entity

  

Here I wrote mybatis: XXXXXX

When I used tkmapper before, there was no problem with writing this here.

 

If you use mybatis plus, write the configuration of mybatis plus here. The problem is solved

[Solved] Mybatis Error: Invalid bound statement (not found)

Error reason: mapper file does not match

Check whether the mapper file is written incorrectly

Check the import configuration of mapper. Note that mapper cannot be imported across packages

Check whether the corresponding mapper file is generated in target/classes. If not, the solution is as follows

Add the following configuration to pom.xml, clean and recompile

</build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.*</include>
            </includes>
        </resource>
    </resources>
</build>

[Solved] Mybatis Error: Invalid bound statement (not found)

Mybatis error reporting: there are many reasons for invalid bound statement (not found), but just like the error reporting prompt, the SQL statement in XML cannot be found. There are three types of error reporting:

The first: syntax error

Java Dao layer interface

public void delete(@Param("id")String id);

Mapper.xml file corresponding to Java

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="xxx.xxx.xxx.Mapper">
    <!-- Delete Datas -->
    <delete id="delete" parameterType="java.lang.String">
        DELETE FROM xxx WHERE id=#{id}
    </delete>
</mapper>

Check:

Is the method name (delete) in the interface consistent with id = "delete" in the XML file

Is the path in namespace = "XXX. XXX. XXX. Mapper" in the XML file consistent with the path in the interface file

Whether the parametertype type and resulttype types are accurate; Resultmap is different from resulttype

 

Second: compilation error

Navigate to the project path: under the error path in target \ classes \ , find out whether the corresponding XML file exists

(1) . if there is no corresponding XML file, you need to add the following code to pom.xml:

<build>
    <resources>
         <resource>
             <directory>src/main/java</directory>
             <excludes>
                 <exclude>**/*.java</exclude>
             </excludes>
         </resource>
         <resource>
             <directory>src/main/resources</directory>
             <includes>
                 <include>**/*.*</include>
             </includes>
        </resource>
    </resources>
</build>

Delete the files in the classes folder, recompile, and the corresponding XML file appears

(2) If there is an XML file, open the XML file and check whether the error part is consistent with the source file. If it is inconsistent,

first clear the files in the classes folder and execute the command: MVN clean clean the content and recompile it

 

Third: configuration error

There was a problem with the configuration path when specifying the scan package in the configuration file

for example, : the package name of the “basepackage” attribute in the spring configuration file must be specific to the package where the interface is located, and do not write the package of the parent level or higher, otherwise problems may occur; Cn. Dao and CN. * may also cause errors; During annotation scanning, packages may not be scanned

[Solved] Springboot Error: invalid bound statement (not found)

1. Overview

An error is reported after springboot starts the web project

invalid bound statement (not found):xxx

2. Problem analysis

This is a very common exception. Error reporting usually includes the following situations:

2.1 syntax error

Mapper.xml does not correspond to Dao correctly

Java Dao interface

public void delete(@Param("id") String id);

Mapper.xml file corresponding to Java

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="xxx.xxx.xxx.xxDao">
    <!-- Delete -->
    <delete id="delete" parameterType="java.lang.String">
        DELETE FROM xxx WHERE id=#{id}
    </delete>
</mapper>

Check and confirm:

a) Whether the interface method name delete is consistent with the id = “delete” in XML

b) Whether the namespace = “XXX. XXX. XXX. Xxxdao” in the XML file is consistent with the path of the interface file (click whether to jump to the corresponding interface class)

 

c) Whether parametertype and resulttype (resultmap) are accurate

2.2 compilation error

Check whether the corresponding mapper.xml file exists under the project target \ classes \ path

If it does not exist, add it in pom.xml

<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>**/*.properties</exclude>
                <exclude>**/*.xml</exclude>
            </excludes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

Recompile and the corresponding XML file will appear (if you want to copy the XML, properties and other configuration files under Src/main/Java to the classes directory, add the above configuration)

two point three   Configuration error

There is a problem with the configuration path when specifying the scan package (mybatis. Mapper locations = classpath *:/XX/XX/mapper/*. XML) in the configuration file