17
17
18
18
import jakarta .persistence .ManyToOne ;
19
19
import jakarta .persistence .MappedSuperclass ;
20
- import jakarta .persistence .Temporal ;
21
- import jakarta .persistence .TemporalType ;
22
20
23
21
import java .io .Serializable ;
22
+ import java .time .Instant ;
24
23
import java .time .LocalDateTime ;
25
24
import java .time .ZoneId ;
26
- import java .util .Date ;
27
25
import java .util .Optional ;
28
26
29
27
import org .springframework .data .domain .Auditable ;
@@ -45,14 +43,12 @@ public abstract class AbstractAuditable<U, PK extends Serializable> extends Abst
45
43
@ ManyToOne //
46
44
private @ Nullable U createdBy ;
47
45
48
- @ Temporal (TemporalType .TIMESTAMP ) //
49
- private @ Nullable Date createdDate ;
46
+ private @ Nullable Instant createdDate ;
50
47
51
48
@ ManyToOne //
52
49
private @ Nullable U lastModifiedBy ;
53
50
54
- @ Temporal (TemporalType .TIMESTAMP ) //
55
- private @ Nullable Date lastModifiedDate ;
51
+ private @ Nullable Instant lastModifiedDate ;
56
52
57
53
@ Override
58
54
public Optional <U > getCreatedBy () {
@@ -67,12 +63,12 @@ public void setCreatedBy(U createdBy) {
67
63
@ Override
68
64
public Optional <LocalDateTime > getCreatedDate () {
69
65
return null == createdDate ? Optional .empty ()
70
- : Optional .of (LocalDateTime .ofInstant (createdDate . toInstant () , ZoneId .systemDefault ()));
66
+ : Optional .of (LocalDateTime .ofInstant (createdDate , ZoneId .systemDefault ()));
71
67
}
72
68
73
69
@ Override
74
70
public void setCreatedDate (LocalDateTime createdDate ) {
75
- this .createdDate = Date . from ( createdDate .atZone (ZoneId .systemDefault ()).toInstant () );
71
+ this .createdDate = createdDate .atZone (ZoneId .systemDefault ()).toInstant ();
76
72
}
77
73
78
74
@ Override
@@ -88,11 +84,11 @@ public void setLastModifiedBy(U lastModifiedBy) {
88
84
@ Override
89
85
public Optional <LocalDateTime > getLastModifiedDate () {
90
86
return null == lastModifiedDate ? Optional .empty ()
91
- : Optional .of (LocalDateTime .ofInstant (lastModifiedDate . toInstant () , ZoneId .systemDefault ()));
87
+ : Optional .of (LocalDateTime .ofInstant (lastModifiedDate , ZoneId .systemDefault ()));
92
88
}
93
89
94
90
@ Override
95
91
public void setLastModifiedDate (LocalDateTime lastModifiedDate ) {
96
- this .lastModifiedDate = Date . from ( lastModifiedDate .atZone (ZoneId .systemDefault ()).toInstant () );
92
+ this .lastModifiedDate = lastModifiedDate .atZone (ZoneId .systemDefault ()).toInstant ();
97
93
}
98
94
}
0 commit comments