Files
rosetta-wss/src/main/java/com/rosetta/im/database/CreateUpdateEntity.java

43 lines
995 B
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.rosetta.im.database;
import java.time.LocalDateTime;
import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.PrePersist;
import jakarta.persistence.PreUpdate;
/**
* Базовый класс для сущностей с полями
* времени создания и обновления
*/
@MappedSuperclass
public class CreateUpdateEntity {
@Column(name = "createdAt", nullable = false, updatable = false)
private LocalDateTime createdAt;
@Column(name = "updatedAt", nullable = false)
private LocalDateTime updatedAt;
@PrePersist
protected void onCreate() {
createdAt = LocalDateTime.now();
updatedAt = LocalDateTime.now();
}
@PreUpdate
protected void onUpdate() {
updatedAt = LocalDateTime.now();
}
public LocalDateTime getCreatedAt() {
return createdAt;
}
public LocalDateTime getUpdatedAt() {
return updatedAt;
}
}