@LastModifiedDate在删除时未更新

时间:2020-05-17 11:39:34

标签: java oracle hibernate jpa

我有一个Entity类Bar,它扩展了AuditEntity

当我插入新记录时,正确插入了created_atupdated_at的时间戳。

但是当我删除记录时,时间戳没有更新,并且与记录插入时间戳相同。

示例:

已插入记录

表格: BAR_AUD

ID  BAR_ID          REVTYPE     created_at              updated_at
1   171             0           11:09:40.965000000 AM   17-05-20 11:09:40.965000000 AM

记录已删除

表格: BAR_AUD

ID  BAR_ID          REVTYPE     created_at              updated_at
1   171             2           11:09:40.965000000 AM   17-05-20 11:09:40.965000000 AM // No change

Bar.java

import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.hibernate.envers.Audited;

@javax.persistence.Entity
@Audited
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"}, ignoreUnknown = true)
@Table(name = "Bar")
@Getter @Setter         // Auto getter setter using lombok api
public class Bar extends AuditEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "bar_generator")
    private long id;

    @Column(nullable = false)
    private String name

}

AuditEntity.java

@Audited
@MappedSuperclass
abstract class AuditEntity {

    @CreatedDate
    @Column(name = "created_at", nullable = false, updatable = false)
    private Date createdAt;

    @LastModifiedDate
    @Column(name = "updated_at", nullable = false)
    private Date updatedAt;

    @Size(max = 30)
    @CreatedBy
    @Column(name = "created_by", nullable = false, updatable = false)
    private String createdBy;

    @Size(max = 30)
    @LastModifiedBy
    @Column(name = "updated_by", nullable = false)
    private String updatedBy;

    @JsonIgnore
    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

    public void setCreatedBy(final String createdBy) {
        this.createdBy = createdBy;
    }

    @JsonIgnore
    public String getCreatedBy() {
        return createdBy;
    }

}

我想念什么?

0 个答案:

没有答案