### Error building SqlSession. ### The error may exist in com/imooc/config/sqlxml/Message.xml
错误信息:
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in com/imooc/config/sqlxml/Message.xml
### The error occurred while processing mapper_resultMap[MessageResult]
### 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/imooc/config/sqlxml/Message.xml'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'VARCHAR'. Cause: java.lang.ClassNotFoundException: Cannot find class: VARCHAR
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:36)
at com.imooc.db.DBAccess.getSqlSession(DBAccess.java:21)
at com.imooc.dao.MessageDao.queryMessageList(MessageDao.java:32)
at com.imooc.dao.MessageDao.main(MessageDao.java:48)
<?xml version="1.0" encoding="UTF-8" ?>
configuration的代码
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- <settings>
<setting name="useGeneratedKeys" value="false"/>
<setting name="useColumnLabel" value="true"/>
</settings>
<typeAliases>
<typeAlias alias="UserAlias" type="org.apache.ibatis.submitted.complex_property.User"/>
</typeAliases>
-->
<environments default="development">
<environment id="development">
<transactionManager type="JDBC">
<property name="" value=""/>
</transactionManager>
<dataSource type="UNPOOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://127.0.0.1:3306/test"/>
<property name="username" value="root"/>
<property name="password" value="1234"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="com/imooc/config/sqlxml/Message.xml"/>
</mappers>
</configuration>
message.xml代码
<?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="Message">
<resultMap type="com.imooc.bean.Message" id="MessageResult">
<id column="ID" jdbcType="INTEGER" property="id" />
<result column="COMMAND" javaType="VARCHAR" property="command" />
<result column="DESCRIPTION" javaType="VARCHAR" property="description" />
<result column="CONTENT" javaType="VARCHAR" property="content" />
</resultMap>
<select id="queryMessageList" resultMap="MessageResult">
select ID,COMMAND,DESCRIPTION,CONTENT from message where 1=1
</select>
</mapper>
DBAccess 代码
public class DBAccess {
public SqlSession getSqlSession() throws IOException{
//通过配置文件获取数据库连接信息
Reader reader = Resources.getResourceAsReader("com/imooc/config/Configuration.xml");
//通过配置信息来构造一个SqlSessionFactory
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
//通过sqlSessionFactory打开一个会话
SqlSession sqlSession = sqlSessionFactory.openSession();
return sqlSession;
}
}