我使用hibernate的hbm2ddl自动生成模式.这是我的域名:
@Entity
public class Reader {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
Long id;
@Column(nullable=false,unique=true)
String name;
@Enumerated(EnumType.STRING)
Gender gender;
int age;
Date registeredDate = new Date();
// getter and setter ...
}
Run Code Online (Sandbox Code Playgroud)
当我使用hibernate来保存a时reader,它可以正常工作,因为它会产生一个id reader.但是,当我使用jdbcTemplate插入带有纯SQL的记录时,它会报告错误:
org.springframework.dao.DataIntegrityViolationException: StatementCallback;
SQL [insert into reader(name,gender,age) values('Lily','FEMALE',21)];
NULL not allowed for column "ID";
SQL statement:insert into reader(name,gender,age) values('Lily','FEMALE',21) [23502-192];
nested exception is org.h2.jdbc.JdbcSQLException: NULL not allowed for column "ID";
SQL statement: insert into reader(name,gender,age) values('Lily','FEMALE',21) [23502-192]
Run Code Online (Sandbox Code Playgroud)
怎么解决这个?
create table Book (id bigint not null, author …