我正在尝试使用休眠会话将时间日期保存到 mysql,但我无法这样做。我有一个测试类,我还为持久性创建了实体侦听器类,但似乎没有任何效果
@Entity
@EntityListeners(TestListener.class)
@Table(name = "test")
public class Test {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "name")
private String name;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "time_date", nullable = false)
private Date TimeDate;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getTimeDate() {
return TimeDate;
}
@PrePersist
public void setTimeDate(Date TimeDate) {
this.TimeDate = new Date();
}
}
我的监听类是:
public class TestListener {
@PrePersist
public void setTimeDate(Test o) {
o.setTimeDate( new Date() );
}
}