使用&#34时,Hibernate创建没有名称的列;更新CURRENT_TIMESTAMP"时默认为CURRENT_TIMESTAMP

时间:2012-12-03 08:06:29

标签: hibernate

我有以下实体:

@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,timestamp default CURRENT_TIMESTAMP on更新CURRENT_TIMESTAMP非null,用户varchar(100)不为null,vorname varchar(255)not null,主键(id))type = MyISAM

有谁知道为什么hibernate会这样做?

1 个答案:

答案 0 :(得分:6)

它不是没有名称的列,它是没有类型的列。

Hibernate期望columnDefinition也包含列类型:

@Temporal(TemporalType.TIMESTAMP)
@Column(name="timestamp", nullable = false,
    columnDefinition="TIMESTAMP default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP")
private Date timestamp = new Date();