I use springboot + mybatis and run with the SpringJUnit4ClassRunner, use the default database h2, and the scripts:
create table sql:
create TABLE IF NOT EXISTS `test_company` (
`id` bigint unsigned not null auto_increment,
`pid` bigint DEFAULT null COMMENT '',
`outer_id` bigint DEFAULT null COMMENT '',
`name` VARCHAR(256) DEFAULT NULL COMMENT '',
`parent_company_name` VARCHAR(256) DEFAULT NULL COMMENT '',
`user_id` bigint DEFAULT NULL COMMENT '用户ID',
`user_name` VARCHAR(64) DEFAULT NULL COMMENT '',
`type` INTEGER DEFAULT null COMMENT '',
`level` INTEGER DEFAULT null COMMENT '',
`status` INTEGER DEFAULT null COMMENT ''
);
the model Company:
@Data
@NoArgsConstructor
public class Company implements Serializable {
private static final long serialVersionUID = -5822686079080905768L;
private Long id; private Long pid;
private Long outerId;
private String name;
private String parentCompanyName;
private Long userId;
private String userName;
private Integer type;
private Integer level;
private Integer status;
}
the resultMap of mapper:
<resultMap id="CompanyMap" type="Company">
<id column="id" property="id"/>
<result column="pid" property="pid"/>
<result column="outer_id" property="outerId"/>
<result column="name" property="name"/>
<result column="parent_company_name" property="parentCompanyName"/>
<result column="user_id" property="userId"/>
<result column="user_name" property="userName"/>
<result column="type" property="type"/>
<result column="level" property="level"/>
<result column="status" property="status"/>
</result>
some sqls:
<sql id="tb">
test_company
</sql>
<sql id="cols_all">
id, <include refid="cols_exclude_id" />
</sql>
<sql id="cols_exclude_id">
pid, outer_id, `name`, `parent_company_name`, user_id, user_name, `type`, `level`, status
</sql>
<sql id="vals">
#{pid}, #{outerId}, #{name}, #{parentCompanyName}, #{userId}, #{userName}, #{type}, #{level}, #{status}
</sql>
create sql:
<insert id="create" parameterType="Company" keyProperty="id" useGeneratedKeys="true">
INSERT INTO
<include refid="tb" />
(<include refid="cols_exclude_id" />)
VALUES
(<include refid="vals" />)
</insert>
it runs well before there is not the column parent_company_name
,
but when I added the column parent_company_name
and rerun the DAO method with create it had this error
org.springframework.jdbc.BadSqlGrammarException:
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'parent_company_name' in 'field list'
### The error may involve Company.create-Inline
### The error occurred while setting parameters
my IDE was IntelliJ IDEA, I don't know if it caused by the cache or something else, I just added a new column and checked all sql scripts was correct.