Skip to content

Instantly share code, notes, and snippets.

@Ikhiloya
Created July 2, 2018 08:42
Show Gist options
  • Select an option

  • Save Ikhiloya/4bec0ca0fe59c9d8b177c73e2786ae05 to your computer and use it in GitHub Desktop.

Select an option

Save Ikhiloya/4bec0ca0fe59c9d8b177c73e2786ae05 to your computer and use it in GitHub Desktop.
An abstract class that with Jpa Auditing
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(
value = {"createdAt", "updatedAt"},
allowGetters = true
)
public abstract class AuditModel implements Serializable {
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "created_at", nullable = false, updatable = false)
@CreatedDate
private Date createdAt;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "updated_at", nullable = false)
@LastModifiedDate
private Date updatedAt;
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment