mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-12 16:38:48 +00:00
71 lines
2.2 KiB
Java
71 lines
2.2 KiB
Java
package com.imprimelibros.erp.common.jpa;
|
|
|
|
import jakarta.persistence.*;
|
|
import org.springframework.data.annotation.CreatedBy;
|
|
import org.springframework.data.annotation.CreatedDate;
|
|
import org.springframework.data.annotation.LastModifiedBy;
|
|
import org.springframework.data.annotation.LastModifiedDate;
|
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|
|
|
import java.time.Instant;
|
|
|
|
import com.imprimelibros.erp.users.User;
|
|
|
|
@MappedSuperclass
|
|
@EntityListeners(AuditingEntityListener.class)
|
|
public abstract class AbstractAuditedSoftDeleteEntity {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long id;
|
|
|
|
// Auditoría temporal
|
|
@CreatedDate
|
|
@Column(name = "created_at", updatable = false)
|
|
private Instant createdAt;
|
|
|
|
@LastModifiedDate
|
|
@Column(name = "updated_at")
|
|
private Instant updatedAt;
|
|
|
|
// Auditoría por usuario (nullable si público anónimo)
|
|
@CreatedBy
|
|
@ManyToOne(fetch = FetchType.LAZY)
|
|
@JoinColumn(name = "created_by")
|
|
private User createdBy;
|
|
|
|
@LastModifiedBy
|
|
@ManyToOne(fetch = FetchType.LAZY)
|
|
@JoinColumn(name = "updated_by")
|
|
private User updatedBy;
|
|
|
|
// Soft delete
|
|
@Column(name = "deleted", nullable = false)
|
|
private boolean deleted = false;
|
|
|
|
@Column(name = "deleted_at")
|
|
private Instant deletedAt;
|
|
|
|
// Getters/Setters
|
|
public Long getId() { return id; }
|
|
public void setId(Long id) { this.id = id; }
|
|
|
|
public Instant getCreatedAt() { return createdAt; }
|
|
public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }
|
|
|
|
public Instant getUpdatedAt() { return updatedAt; }
|
|
public void setUpdatedAt(Instant updatedAt) { this.updatedAt = updatedAt; }
|
|
|
|
public User getCreatedBy() { return createdBy; }
|
|
public void setCreatedBy(User createdBy) { this.createdBy = createdBy; }
|
|
|
|
public User getUpdatedBy() { return updatedBy; }
|
|
public void setUpdatedBy(User updatedBy) { this.updatedBy = updatedBy; }
|
|
|
|
public boolean isDeleted() { return deleted; }
|
|
public void setDeleted(boolean deleted) { this.deleted = deleted; }
|
|
|
|
public Instant getDeletedAt() { return deletedAt; }
|
|
public void setDeletedAt(Instant deletedAt) { this.deletedAt = deletedAt; }
|
|
}
|