Error attempting to get column 'e_gender' from result set

Today encountered an error when using the Query mybatis

Error attempting to get column 'e_gender' from result set.  Cause: java.sql.SQLException: Cannot convert value '男' from column 3 to TIMESTAMP.
; Cannot convert value '男' from column 3 to TIMESTAMP.; nested exception is java.sql.SQLException: Cannot convert value '男' from column 3 to TIMESTAMP.

Check the Internet a lot of solutions, most of them are said to be inconsistent attribute type of database field type and the entity class definition causes, but look:

<resultMap type="com.xyw.hospital.model.entity.Employee" id="BaseMap">
        <result property="eId" column="e_id" jdbcType="INTEGER"/>
        <result property="eName" column="e_name" jdbcType="VARCHAR"/>
        <result property="eGender" column="e_gender" jdbcType="VARCHAR"/>
        <result property="eBirthday" column="e_birthday" jdbcType="TIMESTAMP"/>
        <result property="eDid" column="e_did" jdbcType="INTEGER"/>
        <result property="eRoleid" column="e_roleid" jdbcType="INTEGER"/>
        <result property="eTel" column="e_tel" jdbcType="VARCHAR"/>
        <result property="eVprice" column="e_vprice" jdbcType="NUMERIC"/>
        <result property="eState" column="e_state" jdbcType="INTEGER"/>
        <result property="eCreateTime" column="e_create_time" jdbcType="TIMESTAMP"/>
        <result property="eClossTime" column="e_closs_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="items">
        e_id, e_name, e_gender, e_birthday, e_did, e_roleid, e_tel, e_vprice, e_state, e_create_time, e_closs_time    </sql>
    <!--查询单个-->
    <select id="queryById" resultMap="BaseMap">
        select
          <include refid="items"/>
        from employee
            where e_id = #{eId}
    </select>
CREATE TABLE `employee` (
  `e_id` int(11) NOT NULL AUTO_INCREMENT,
  `e_name` varchar(25) DEFAULT NULL,
  `e_gender` varchar(4) DEFAULT NULL COMMENT '''男''或''女''',
  `e_birthday` date DEFAULT NULL,
  `e_did` int(11) DEFAULT NULL,
  `e_roleid` int(11) DEFAULT NULL,
  `e_tel` varchar(15) DEFAULT NULL,
  `e_vprice` decimal(10,2) DEFAULT NULL,
  `e_state` int(1) DEFAULT '0' COMMENT '0 新注册(默认) 1 在职 2离职',
  `e_create_time` date DEFAULT NULL,
  `e_closs_time` date DEFAULT NULL,
  PRIMARY KEY (`e_id`) USING BTREE,
  KEY `idx_did` (`e_did`) USING BTREE,
  KEY `idx_roleid` (`e_roleid`) USING BTREE,
  KEY `idx_state` (`e_state`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
	protected Integer eId;
    protected String eName;
    protected String eGender;
    protected Date eBirthday;
    protected Integer eDid;
    protected Integer eRoleid;
    protected String eTel;
    protected Double eVprice;
    protected Integer eState;
    protected Date eCreateTime;
    protected Date eClossTime;

    public Employee(String eName, String eGender, Date eBirthday, String eTel, Integer eDid, Integer eRoleid, Double eVprice) {
        //略
    }

We can see a consistent field definitions, resulting in consistent I have been puzzled.

What is the real reason this place is it?

We may have seen, I have here a constructor method, which eliminates the need for a field, causing the excess data found in the data constructor so that it will e_id-> eName, e_name-> eGender, e_gender-> eBirthday, here it is because e_gender vchar, and eBirthday a date type, lead type conversion failed.

Here the type of back problems, questions about the type of conversion is unknown here said. But I remember the definition of a database field must be consistent with the type of entity class field .

The problem here is that assignment will be used when the entity class constructor mybatis assignment is performed, the number of fields is inconsistent if the number of configuration parameters and methods mysql result set, in particular less foregoing parameters, the assignment will assignment in the order, it may be wrong.

Here the solution is simple, add an empty constructor as long as the entity class

public Employee() {
    }

Can, mybatis will give priority to using the most appropriate construction methods assignment, if not find a suitable construction methods will be used empty constructor method, and the result set will look the same field names from the properties of the entity class on assignment property assignment.

It reminds me of when the teacher had previously javaweb always stressed the importance of learning empty constructor, but still can not understand this error I remember when defining the future for pojo class, if there is need to define the parameters of the constructor similar problems, must take the constructor with no arguments to make up, to prevent.

These are my own understanding, may be inconsistent with the real answers, welcome to correct me big brother.

Guess you like

Origin www.cnblogs.com/xywang-35/p/12640000.html