当在"CURRENT_TIMESTAMP更新时使用默认CURRENT_TIMESTAMP"时,Hibernate创建没有名称的列. [英] Hibernate creates column without name when using "default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP"
问题描述
我有以下实体:
@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要创建表时出现错误.似乎发生了错误,因为列时间戳没有名称:
When invoking hibenate , i get an error when hibernate wants to create the table. it seems the errror occurs, beacause the column timestamp has no name:
错误:HHH000389:不成功:创建表Person(id int(11)不为null auto_increment,klasse varchar(20)不为空,名称varchar(255)不为空,密码varchar(255)不为空,时间戳默认为CURRENT_TIMESTAMP更新CURRENT_TIMESTAMP不为null,用户varchar(100)不为null,vorname varchar(255)不为null,主键(id))type = MyISAM
ERROR: HHH000389: Unsuccessful: create table Person (id int(11) not null auto_increment, klasse varchar(20) not null, name varchar(255) not null, password varchar(255) not null, timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP not null, user varchar(100) not null, vorname varchar(255) not null, primary key (id)) type=MyISAM
有人知道为什么冬眠吗?
Does anyone knows why hibernate does this ?
推荐答案
这不是没有名称的列,而是没有类型的列.
It's not a column without name, it's a column without type.
Hibernate希望columnDefinition
也包含列类型:
Hibernate expects that columnDefinition
contains column type as well:
@Temporal(TemporalType.TIMESTAMP)
@Column(name="timestamp", nullable = false,
columnDefinition="TIMESTAMP default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP")
private Date timestamp = new Date();
这篇关于当在"CURRENT_TIMESTAMP更新时使用默认CURRENT_TIMESTAMP"时,Hibernate创建没有名称的列.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!