title: How to define a generic primary key field in base entity?
body: <p>I have created a <code>BaseEntity</code> class which will have all the common fields of the other entities like <code>created_date</code>, <code>created_by</code>, <code>updated_by</code> etc., I also kept primary key <code>id</code> in there. I am using <code>extends</code> and using the fields from base entity class. The main problem is <code>id</code> field is of type <code>Long</code> in some entities and type of <code>String</code> in some other entities, so how can I manage the <code>id</code> field?</p>
  
  <p>Base Entity Class:</p>
  
  <pre><code>@Getter
  @Setter
  @MappedSuperclass
  public abstract class BaseEntity implements Serializable {
  
      private static final long serialVersionUID = 3779027956207925319L;
  
      protected Long id;
      private String createdBy;
      private Date createdDate;
      private String lastUpdatedBy;
      private Date lastUpdatedDate;
      private Boolean isActive;
  
      public abstract Long getId();
      public abstract void setId(Long id);
  
      @Override
      public String toString() {
          return String.format(
                  "BaseEntity [createdBy=%s, createdDate=%s, lastUpdatedBy=%s, lastUpdatedDate=%s, isActive=%s]",
                  createdBy, createdDate, lastUpdatedBy, lastUpdatedDate, isActive);
      }
  }
  </code></pre>