I currently have an Entity as below:
@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long productId;
With the mix of @dimitrisli and @buddha answers, something pretty clean is
@Data
@MappedSuperclass
public abstract class BaseEntity {
@Column(updatable = false)
@CreationTimestamp
private LocalDateTime createdAt;
@UpdateTimestamp
private LocalDateTime updatedAt;
}
And now you all your entity can extend that class like so
@Data
@Entity
@EqualsAndHashCode(callSuper = true)
public class User extends BaseEntity {
@Id
@GeneratedValue
public UUID id;
public String userName;
public String email;
public String firstName;
public String lastName;
}
Note that you might not need @Data & @EqualsAndHashCodeannotation annotations from lombok as it generate getter/setter