This Java code defines a base entity class named BaseEntity
that is intended to be extended by other entities in a Java Persistence API (JPA) based application, likely using a framework like Hibernate
package com.eliasmanj.accoutns.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.time.LocalDateTime;
@Getter
@Setter
@ToString
@MappedSuperclass
public class BaseEntity {
@Column(updatable = false)
private LocalDateTime createdAt;
@Column(updatable = false)
private String createdBy;
@Column(insertable = false)
private LocalDateTime updatedAt;
@Column(insertable = false)
private String updatedBy;
}
@Getter
, @Setter
, and @ToString
annotations are from Lombok, and they automatically generate getter, setter, and toString
methods for the class, reducing boilerplate code.@MappedSuperclass
annotation indicates that this class is a superclass for entities and should not be mapped to a database table itself. Instead, its fields will be inherited by subclasses.createdAt
, createdBy
, updatedAt
, and updatedBy
.@Column
, providing additional information about how these fields should be mapped to database columns.@Column(updatable = false)
indicates that these columns should not be updated when an entity is modified.@Column(insertable = false)
indicates that these columns should not be included when inserting new records.