Performance issues with @MappedSuperClass in JPA entites

Viewed 129

I am using @MappedSuperClass in my project basically to keep all the common fields in a centralized place and also I do not require any table-specific to that class. I have kept fields like Id and other fields which will be used for auditing purposes.

I do not require any records fetched via id for most of the cases.

Will, there be any significant change in performance if I use those fields directly in my entity instead of keeping them in a separate abstract class which all classes will inherit.

Below is the class definition:

@Getter
@Setter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class) // used for auditing purpose
public abstract class AbstractEntity {

    @Id
    @GeneratedValue(generator = "UUID")
    @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
    private String id;

    @JsonIgnore
    @CreatedBy
    @Column(name = "created_by", nullable = false)
    protected String createdBy;

    @JsonIgnore
    @Column(name = "created_at", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    protected Date createdAt;

    @JsonIgnore
    @LastModifiedBy
    @Column(name = "modified_by")
    protected String modifiedBy;

    @JsonIgnore
    @LastModifiedDate
    @Column(name = "modified_at")
    @Temporal(TemporalType.TIMESTAMP)
    protected Date modifiedAt;

    protected AbstractEntity() {
    }
}
1 Answers

No because the underlaying database model will not change.

@MappedSuperclass is only a mechanism to tell JPA/Hibernate to also consider the inherited members.

Related