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.
Read More:
- [Solved] Error building SqlSession.The error may exist in XXXXXMapper/xml
- [Solved] ### Error building SqlSession. ### The error may exist in com/atguigu/dao/SysUserMapper.xml ### Caus
- [Solved] Mybatis Error: Could not find resource mybatis-conf.xml
- [Solved] Mybatis.generator error: Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2
- How to Solve SQL comments error in the mybatis query
- [Solved] Tk-Mybatis Error: tk.mybatis.mapper.MapperException:
- Mybatis single parameter pass in exception (How to Fix)
- Mybatis query error: Exception in thread “main” org.apache.ibatis.exceptions.PersistenceException…
- [Solved] Spring set xml Component Scanning error: Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException…
- Eclipse: How to Close XML validation (xml file Error)
- [Solved] mybatis plus Insert Error: mybatis plus Error setting null for parameter #1 with JdbcType OTHER
- Build a mybatis and it will appear session.selectOne Method error
- o.s.boot.SpringApplication, Error creating bean with name ‘paymentImpl‘, xml Configuration file error
- Mybatis reports an error (error building sqlsession.) when using annotations without deleting redundant files
- Ruoyi-cloud Integrated mybatis-plus Error: Unknown column ‘search_value‘ in ‘field list‘
- How to Solve Error: Error parsing mapper XML
- [Solved] Mybatis Error: Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance.
- Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber
- [Solved] Mybatis Error: attempting to get column ‘XX’ from result set
- [Solved] JavaErrors_mybatis collection column Pass Value Error