我正在使用WildFly,(jboss-javaee-7.0-with-hibernate),JPA(hibernate-jpa-2.1-api),hibernate-jpamodelgen和MySql作为数据库。任何人都可以指导我如何使用@PrePersist或@PreUpdate或其他方式以UTC格式存储日期。
样本模型类:
@Entity
@Audited
@XmlRootElement
@Table(uniqueConstraints = @UniqueConstraint(columnNames = "name"))
@JsonIgnoreProperties(value = { "handler", "hibernateLazyInitializer" })
public class SampleTest {
private static final long serialVersionUID = 1L;
private String name;
private String comment;
private Date createdDate;
private Date lastModifiedDate;
@PrePersist
protected void onCreate() {
createdDate = new Date();
}
@PreUpdate
protected void onUpdate() {
lastModifiedDate = new Date();
}
这不会在数据库中以UTC时区存储创建的日期和上次修改日期。有人可以指导我吗?