我得到了以下实体:
@Entity
public class Person {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(columnDefinition="int(11)",nullable=false)
private int id;
@Column(columnDefinition="varchar(255)",nullable=false)
private String name;
@Column(columnDefinition="varchar(255)",nullable=false)
private String vorname;
@Column(columnDefinition="varchar(255)",nullable=false)
private String password;
@Column(columnDefinition="varchar(100)",nullable=false)
private String user;
@Column(columnDefinition="varchar(20)",nullable=false)
private String klasse;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="timestamp",nullable = false,columnDefinition="default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP")
private Date timestamp = new Date();
public Person(){
}
@PreUpdate
public void updatePerson(){
this.timestamp = new Date();
}
...getters
...setters
}
调用 hibenate 时,当 hibernate 想要创建表时出现错误。似乎发生了错误,因为列时间戳没有名称:
错误:HHH000389:不成功:创建表 Person (id int(11) not null auto_increment,klasse varchar(20) not null,name varchar(255) not null,password varchar(255) not null,时间戳默认 CURRENT_TIMESTAMP 更新 CURRENT_TIMESTAMP 不是null,用户 varchar(100) 不为空,vorname varchar(255) 不为空,主键 (id)) type=MyISAM
有谁知道为什么hibernate会这样做?