//我使用Spring MVC,Mybatis和HSQL实现CRUD操作
//用于生成ID IM尝试使用生成的值标签,但似乎不是//生成
我是Mybatis的新手
<insert id='addEmp1' parameterType='Employee'
useGeneratedKeys='true' keyProperty='E_ID'>
INSERT INTO "PUBLIC"."EMPLOYEE"(
"ADDRESS",
"AGE",
"CITY",
"DEPT",
"FNAME",
"LNAME",
"SALARY",
"STATE")
values(
#{address},
#{age},
#{city},
#{dept},
#{fname},
#{lname},
#{salary},
#{state})
</insert>
//bean class
public class Employee {
public Employee() {
// TODO Auto-generated constructor stub
}
private Long e_id;
@NotBlank(message = "Name is Mandatory")
private String fname;
private String lname;
@NotNull(message = "Age is Mandatory")
@Range(min = 18, max = 99, message = "Age should be between 18 and 99")
private Integer age;
@NotNull(message = "salary may not be empty")
@Range(min = 1)
private Integer salary;
@NotBlank(message = "")
@NotEmpty(message = "Select one Department")
private String dept;
@NotBlank(message = "Select atleast one state")
private String state;
@NotBlank(message = "Select atleast one City")
private String city;
@NotEmpty(message = "At least one Skill is required")
@Valid
@ElementCollection(fetch = FetchType.EAGER)
private List<String> skills = new ArrayList<String>();
private String address;
//stacktrace显示为null的ID(应自动生成(
### Error updating database. Cause:
java.sql.SQLIntegrityConstraintViolationException: integrity constraint
violation: NOT NULL check constraint; SYS_CT_10226 table: EMPLOYEE column:
E_ID
### The error may exist in com/jamocha/DAO/EmployeeMapper.xml
### The error may involve com.jamocha.DAO.EmployeeDAO.addEmp1-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO "PUBLIC"."EMPLOYEE"( "ADDRESS", "AGE", "CITY",
"DEPT", "FNAME","LNAME", "SALARY", "STATE") values(?,?,?,?,?,?,?,?)
### Cause: java.sql.SQLIntegrityConstraintViolationException: integrity
constraint violation: NOT NULL check constraint; SYS_CT_10226 table:
EMPLOYEE column: E_ID] with root cause
java.sql.SQLIntegrityConstraintViolationException: integrity constraint
violation: NOT NULL check constraint; SYS_CT_10226 table: EMPLOYEE column:
E_ID
我认为插入标签中的属性引起的问题。请尝试以下映射
<insert id='addEmp1' parameterType='Employee' useGeneratedKeys='true'
keyProperty='e_id' keyColumn='E_ID'>
INSERT INTO "PUBLIC"."EMPLOYEE"(
"ADDRESS",
"AGE",
"CITY",
"DEPT",
"FNAME",
"LNAME",
"SALARY",
"STATE")
values(
#{address},
#{age},
#{city},
#{dept},
#{fname},
#{lname},
#{salary},
#{state})
</insert>
请注意,键盘(CASE敏感(和密钥列属性的更改。有关我的信息,请参考http://www.mybatis.org/mybatis-3/sqlmap-xml.html#insert.2c_update_and_delete有关更多详细信息。