Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自动时间戳更新在hibernate中不起作用_Hibernate_Annotations - Fatal编程技术网

自动时间戳更新在hibernate中不起作用

自动时间戳更新在hibernate中不起作用,hibernate,annotations,Hibernate,Annotations,嗨 我的POJO班是 @Entity @Table(name = "seed") public class SeedUrl { @Id SeedUrlPrimaryKey primaryKey = new SeedUrlPrimaryKey(); @Temporal(TemporalType.TIMESTAMP) @Column private Date lastUpdated; public SeedUrl(String url){

我的POJO班是

@Entity
@Table(name = "seed")
public class SeedUrl {

    @Id
    SeedUrlPrimaryKey primaryKey = new SeedUrlPrimaryKey();

     @Temporal(TemporalType.TIMESTAMP)
    @Column
    private Date lastUpdated;



    public SeedUrl(String url){
        this.url = url;
    }
    public SeedUrl(){}

    public SeedUrlPrimaryKey getPrimaryKey() {
        return primaryKey;
    }

    public void setPrimaryKey(SeedUrlPrimaryKey primaryKey) {
        this.primaryKey = primaryKey;
    }


    @PrePersist
    @PreUpdate
    public void onLastUpdated() {
        this.lastUpdated = new Date();
    }
}
我想在插入或更新时更新同一列

我正在按如下方式保存对象:

SeedUrlPrimaryKey primaryKey = new SeedUrlPrimaryKey();
            primaryKey.setSeedId("111121123");
            seedUrl.setPrimaryKey(primaryKey);
            session.save(seedUrl);
                    session.getTransaction().commit()
但在数据库中,lastUpdated的值为null。。 在DB中,列被声明为时间戳。

我哪里出错了?

当您通过
会话
接口使用Hibernate时,JPA回调方法(
@PrePersist
等)不起作用。您可以使用