Tag Archives: Mybatis error

Mybatis Error: Error instantiating class bakou.entity.Person with invalid types () or value)

Error instantiating class bakou.entity.Person with invalid types () or values (). Cause: java.lang.NoSuchMethodException: bakou.entity.Person.<init>()


Reason: Only a parameterized constructor is added to the entity class, no parameterless constructor is provided

Solution: Add a construction method in the entity class without parameters

The essence of the problem: Instantiate the object with a method that uses an uninvolved construct to instantiate the object


The error page is as follows:

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating class bakou.entity.Person with invalid types () or values (). Cause: java.lang.NoSuchMethodException: bakou.entity.Person.<init>()
### The error may exist in bakou/dao/PersonDaoMapper.xml
### The error may involve bakou.dao.PersonDao.selectById-Inline
### The error occurred while setting parameters
### SQL: select p.id,name,phone,c.id cid,cardno,address,expire         from person p                  join card c         on p.card_id = c.id where p.id = ?;
### Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating class bakou.entity.Person with invalid types () or values (). Cause: java.lang.NoSuchMethodException: bakou.entity.Person.<init>()

	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:95)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:59)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:95)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40)
	at com.sun.proxy.$Proxy5.selectById(Unknown Source)
	at bakou.test.TestPersonDao.testPersonDao(TestPersonDao.java:21)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: org.apache.ibatis.reflection.ReflectionException: Error instantiating class bakou.entity.Person with invalid types () or values (). Cause: java.lang.NoSuchMethodException: bakou.entity.Person.<init>()
	at org.apache.ibatis.reflection.factory.DefaultObjectFactory.instantiateClass(DefaultObjectFactory.java:83)
	at org.apache.ibatis.reflection.factory.DefaultObjectFactory.create(DefaultObjectFactory.java:45)
	at org.apache.ibatis.reflection.factory.DefaultObjectFactory.create(DefaultObjectFactory.java:38)
	at org.apache.ibatis.executor.resultset.FastResultSetHandler.createResultObject(FastResultSetHandler.java:376)
	at org.apache.ibatis.executor.resultset.FastResultSetHandler.createResultObject(FastResultSetHandler.java:355)
	at org.apache.ibatis.executor.resultset.NestedResultSetHandler.getRowValue(NestedResultSetHandler.java:137)
	at org.apache.ibatis.executor.resultset.NestedResultSetHandler.getRowValue(NestedResultSetHandler.java:122)
	at org.apache.ibatis.executor.resultset.NestedResultSetHandler.handleRowValues(NestedResultSetHandler.java:108)
	at org.apache.ibatis.executor.resultset.NestedResultSetHandler.handleResultSet(NestedResultSetHandler.java:76)
	at org.apache.ibatis.executor.resultset.FastResultSetHandler.handleResultSets(FastResultSetHandler.java:152)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:57)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:70)
	at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:57)
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:141)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:101)
	... 34 more
Caused by: java.lang.NoSuchMethodException: bakou.entity.Person.<init>()
	at java.lang.Class.getConstructor0(Class.java:3082)
	at java.lang.Class.getDeclaredConstructor(Class.java:2178)
	at org.apache.ibatis.reflection.factory.DefaultObjectFactory.instantiateClass(DefaultObjectFactory.java:57)
	... 51 more

The solution is as follows (no parameter structure is provided)

    public Person() {
    }

    public Person(Integer personId, String name, String phone, Card card) {
        this.personId = personId;
        this.name = name;
        this.phone = phone;
        this.card = card;
    }

[Solved] Mybatis Error: Resources.getResourceAsStream(resource) cannot find the method

Problem Description: mybatisdemo.java
when loading the core configuration file of mybatis and obtaining SqlSessionFactory, the getResourceAsStream() method is marked in red, and the idea indicates that there is no such method.

1, Load the core configuration file of mybatis and get the SqlSessionFactory
    String resource = "mybatis-config.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    
Error:Cannot resolve method ‘getResourceAsStream‘ in ‘Resources‘

Solution: import import.org.apache.ibatis.io.Resources

~~

If the error is still reported, it will display: org.apache.ibatis.io does not exist, check the setting information of Maven.

1. First, open the installation root directory of Maven and find settings.xml

Set up the storage repository in settings.xml:
<localRepository>E:\maven\apache-maven-3.6.1\mvn_repo</localRepository>

2. Enter the IDE and make settings
File-Settings-Build,Execution,Depolyment-BuildTools-Maven
take the following configuration as an example:

At this time, the problem was solved!

[Solved] Mybatis Error: CannotFindDataSourceException: dynamic-datasource can not find primary datasource

Problem background

When using mybatis, an error is reported that the master data source cannot be found:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: com.baomidou.dynamic.datasource.exception.CannotFindDataSourceException: dynamic-datasource can not find primary datasource
### The error may exist in com/lanran/transactional/dao/PaymentMapper.java (best guess)
### The error may involve com.lanran.transactional.dao.PaymentMapper.insertBatchSomeColumn
### The error occurred while executing an update
### Cause: com.baomidou.dynamic.datasource.exception.CannotFindDataSourceException: dynamic-datasource can not find primary datasource

Solution

1. Because the multi-source configuration dependency of mybatisplus is added, but the configuration file does not write the related configuration of multi-source, an error is reported

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
            <version>3.5.0</version>
        </dependency>

Method 1: if you don’t use multi-source configuration, remove this dependency
Method 2:  application set multi-source configuration

server:
  port: 40001

spring:
  datasource:
    druid:
      stat-view-servlet:
        enabled: true
    dynamic:
      # Configure the global druid parameter, please configure as needed
      druid:
        initial-size: 5
        max-active: 8
        min-idle: 3
        max-wait: 1000
        validation-query: 'select 1'
      datasource:
        master:
          username: root
          password: 123456
          url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
          driver-class-name: com.mysql.cj.jdbc.Driver
        slave_1:
          username: root
          password: 123456
          url: jdbc:mysql://localhost:3306/test2?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
          driver-class-name: com.mysql.cj.jdbc.Driver

[Solved] Mybatis Error: Could not find resource mybatis-conf.xml

Mybatis reports an error: could not find resource mybatis-conf.xml

Screenshot of error reporting:

Error content:

java.io.IOException: Could not find resource mybatis-conf.xml at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:114) at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:100) at org.apache.ibatis.io.Resources.getResourceAsReader(Resources.java:160) at MybatisAdvancedTest.testQueryByNo(MybatisAdvancedTest.java:23)

The default solution is that his article is compiled in the ide-src-jebat.xml directory, which is not posted on my ide-jebat When the XML file is in the resources directory, debug goes in to watch the process and finds resources Getresourceasreader is not loaded into this XML configuration file at all

Code diagram:

// Query a student based on their school number @Test public void testQueryByNo() throws IOException { String resource = "mybatis-conf.xml"; Reader reader = Resources. getResourceAsReader(resource); SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader); SqlSession session = sessionFactory.openSession(); // pass in the StudentMapper interface, return the mapper proxy object studentMapper studentMapper = session.getMapper( StudentMapper.class);//interface //pass the mapper proxy object studentMapper to call the methods in the ISTudentMapper interface Student student = studentMapper.queryStudentByNo(1); System.out.println(student+"****"); session.close(); }

Solution 1:

Replace this part of the code in the test method above:

String resource = "mybatis-conf.xml"; Reader reader = Resources.getResourceAsReader(resource);

Replace with

Reader reader = Resources.getResourceAsReader("mybatis-conf.xml");

If the xml is not compiled properly by idea, such as IDEA development, but not mybatis-config.xml in the resources directory, for example, in src/main/java, then add the build code at the end of pom.xml to tell idea to compile our configuration file:

Solution 2:

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

Solution 3:

Move the configuration file to the resources directory and rebuild our project

[Solved] mybatis Error: Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance.

java.lang.ExceptionInInitializerError
	at com.example.dao.UserDaoTest.test(UserDaoTest.java:12)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:221)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 18; 1 字节的 UTF-8 序列的字节 1 无效。
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
	at com.example.util.MybatisUtils.<clinit>(MybatisUtils.java:19)
	... 26 more
Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 18; 1 字节的 UTF-8 序列的字节 1 无效。
	at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:263)
	at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:127)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.<init>(XMLConfigBuilder.java:81)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:77)
	... 28 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 18; 1 字节的 UTF-8 序列的字节 1 无效。
	at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:204)
	at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:178)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:306)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1000)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:534)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at java.xml/com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:246)
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
	at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:261)
	... 31 more
Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 1 字节的 UTF-8 序列的字节 1 无效。
	at java.xml/com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:702)
	at java.xml/com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:568)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1904)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanData(XMLEntityScanner.java:1377)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLScanner.scanComment(XMLScanner.java:800)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanComment(XMLDocumentFragmentScannerImpl.java:1069)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:883)
	... 39 more

Solution:

Change UTF-8 in the XML of all configuration files to utf8

After modification, you can query it.

[Solved] Mybatis Error: Establishing SSL connection without server‘s identity verification is not recommended.

Mybatis Error: Establishing SSL connection without server‘s identity verification is not recommended.

 

Solution:

(1) You need to explicitly disable SSL by setting usessl = false, or set usessl = true and provide a truststore for server certificate validation
(2) at this time, we only need to set usessl = false on the URL connecting to the database.

[Solved] Mybatis Error: Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance.


Complete error reporting:

org.apache.ibatis.exceptions.PersistenceException: 
Error building SqlSession.
Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 58; columnNumber: 17; 元素类型为 "configuration" 的内容必须匹配 "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,reflectorFactory?,plugins?,environments?,databaseIdProvider?,mappers?)"。

Solution:

When the above error occurs, it is obvious that the exception occurs when parsing the XML configuration file,
from org.xml.sax.saxparseexception; lineNumber: 30; columnNumber: 17; Content with element type “configuration” must match: (properties?, settings?, typealiases?, typehandlers?, objectfactory?, objectwrapperfactory?, plugins?, environments?, databaseidprovider?, mappers?) “。 It is obvious that the configuration files of mybatis are in order and the number is limited Indicates that there can be no but at most one, but in your own configuration:

Incrrect order:

Correct order:

How to Solve Mybatis error: invalid bound statement (not found)

Solve the mybatis error invalid bound statement (not found)

Reason for this error

1. XML file does not exist

2. The XML file and mapper are not mapped

Namespace specifies the path of mapper. The error ID is inconsistent with the method name in mapper

3. The XML file is in the Java directory instead of the resource directory, so there is no XML in the generated target

Scene

When using the mybatis plus framework, when customizing the mapper interface and XM file, because the MP automatic code generation plug-in is used, the mapper interface and XML file are in the Java directory. During compilation, the XML file under the Java path will not be automatically compiled, and the compilation will only identify the. Java file, Only XML files under resource can be compiled when packaged.

The following figure shows the XML and mapper directories of the MP auto generated code plug-in (no longer in the resource)

The compiled target directory is as follows:

Solution:

1. Add in POM file

    <build>
        <!-- The *.xml file in the java directory will also be packaged when the project is packaged -->
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>

2. Manually move the XML file in the Java directory to the resource directory and add it to the configuration file in spring boot

mybatis-plus:
	mapper-locations: classpath:**/*.xml //After the classpath add the directory of your xml file

The directory in mapper locations must be consistent with the directory where you place XML files, otherwise this error will occur even if there are XML files in target!!!

Mybatis Error: The error may exist in xxxxMapper.xml [How to Solve]

After learning mybatis, this exception is reported during one-to-one mapping

### Error building SqlSession.
### The error may exist in StudentMapper.xml
### The error occurred while processing mapper_resultMap[AddressResult]
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'StudentMapper.xml'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Address'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Address

In fact, the exception report is quite clear. This is the mapping file, that is, the code in studentmapper.xml

	<resultMap id="selectStudentResult1" type="Student">
		<id property="studId" column="id"/>
		<result property="name" column="name"/>
		<result property="email" column="email"/>
		<result property="dob" column="dob"/>
		<result property="phone" column="phone"/>
		<association property="address" resultMap="AddressResult"/>
	</resultMap>

//Note the type of the following line
	<resultMap id="AddressResult" type="Address">
		<id property="addrId" column="addr_id"/>
		<result property="street" column="street"/>
		<result property="city" column="city"/>
		<result property="state" column="state"/>
		<result property="zip" column="zip"/>
		<result property="country" column="country"/>

	</resultMap>

	<! -- This is used to test one-to-one ResultMap One-to-one mapping of better method nesting results -->
	<select id="selectStudentWithAddress1" parameterType="int" resultMap="selectStudentResult1">
		select id,name,email,dob,phone,
		street,city,state,zip,country from students s left join addresses a
		on s.addr_id = a.addr_id
		where id = #{id}
	</select>

There are also corresponding files

The reason for my error is mybatis-config.xml in the configuration file. There is no alias for address. (because the type attribute in the resultmap uses address, the alias is called address)
(the type attribute is the fully qualified name of the class. Add address)

	<typeAliases>
		<typeAlias type="Full name" alias="Student" />
<!--		<typeAlias type="Full name" alias="Address"/>-->
	</typeAliases>

In this tab, you can also use package to set the default name of all classes in a directory
(if you use package, you don’t need to add the class name)

	<typeAliases>
		<package name="Full qualified name without class name" />
	</typeAliases>

This will work properly.

[Solved] Mybatis Error: Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration.

Testing Mybatis, querying data, reporting errors.
### Error building SqlSession
### The error may exist in com/lxc/dao/UserMapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is ‘com/lxc/dao/UserMapper.xml’. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias ‘User’.  Cause: java.lang.ClassNotFoundException: Cannot find class: User
The green circle in the screenshot below is the error file, look further back Cannot find class: User , indicating that the class was not found

In looking at the error file configuration.
Locate the error place, should write the full path

Solution:

Mybatis error under Springboot project: Invalid bound statement (not found)

Mybatis reports an error: Invalid bound statement (not found). There are many reasons, but just like the error message, the SQL statement in the xml cannot be found. There are three situations in which the error is reported:

The first type: grammatical 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 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 id=”delete” in the xml file

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

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

The second: compilation error

Locate the project path: under the error path in target\classes\, and look for the corresponding xml file.

(1) If there is no corresponding xml file, you need to add the following code in 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 will appear.

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

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

  When specifying the scan package in the configuration file, there is a problem with the configuration path. For example: the “basePackage” attribute package name specified in the spring configuration file must be specific to the package where the interface is located, instead of writing the parent or higher level package, otherwise problems may occur; cn.dao and cn.* may also cause errors ; When the annotation is scanned, the package may not be scanned.

Mybatis Error: Cause: java.sql.SQLException: sql injection violation, syntax error: syntax error, expect EQ

1. The screenshot of error report is as follows:

2. According to the error report output, check the position after the token, which appears near the ID field. The reason is that after LZ updates the last attribute of the statement, there is an extra comma in front of the where keyword.

3. Solutions

Remove the comma in the red box in the screenshot of step 1.