'Is there a @LastAccessedTimestamp in JPA
I want to store the last read time in a Date column when ever someone tries to load or fetch(select query, findBy methods) a entity
I had a look at @PostLoad
as explained in this site . Have following questions :-
(a)Just want to know if this is safe to Update entity in @PostLoad
(b) Is there something like @LastAcessedTime
in JPA similar to @UpdateTimestamp
?
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.time.LocalDate;
@Data
@Entity
public class SensitiveInfo {
@Id
private Long id;
private String data;
@CreationTimestamp
private LocalDate createdDate;
@UpdateTimestamp
private LocalDate updationTimeStamp;
// Is there a JPA automatic way to Update this field any time hibernate loads this entity ?
private LocalDate updationTimeStamp;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|