Hello I am using Jhipster to generate my backend code and I'm trying to add auditing fields to my entities, I am aware that my custom entity should extend the AbstractAuditingEntity
class, but the added fields are not showing in the database but are showing in JPA, do you know how can I solve the issue?
here is the code of the Abstract auditing entity class generated by Jhipster
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = { "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate" }, allowGetters = true)
public abstract class AbstractAuditingEntity<T> implements Serializable {
private static final long serialVersionUID = 1L;
public abstract T getId();
@CreatedBy
@Column(name = "created_by", nullable = false, length = 50, updatable = false)
private String createdBy;
@CreatedDate
@Column(name = "created_date", updatable = false)
private Instant createdDate = Instant.now();
@LastModifiedBy
@Column(name = "last_modified_by", length = 50)
private String lastModifiedBy;
@LastModifiedDate
@Column(name = "last_modified_date")
private Instant lastModifiedDate = Instant.now();
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public Instant getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Instant createdDate) {
this.createdDate = createdDate;
}
public String getLastModifiedBy() {
return lastModifiedBy;
}
public void setLastModifiedBy(String lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
public Instant getLastModifiedDate() {
return lastModifiedDate;
}
public void setLastModifiedDate(Instant lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
}
and here the custom entity code
@Entity
@Table(name = "indicator")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@SuppressWarnings("common-java:DuplicatedBlocks")
public class Indicator extends AbstractAuditingEntity<Long> implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@Column(name = "id")
private Long id;
@NotNull
@Column(name = "code", nullable = false, unique = true)
private Integer code;
@NotNull
@Size(max = 50)
@Column(name = "title", length = 50, nullable = false)
private String title;
@NotNull
@Size(max = 50)
@Column(name = "titlear", length = 50, nullable = false)
private String titlear;
@NotNull
@Size(max = 50)
@Column(name = "titlefr", length = 50, nullable = false)
private String titlefr;
@Size(max = 500)
@Column(name = "description", length = 500)
private String description;
@Size(max = 500)
@Column(name = "descriptionar", length = 500)
private String descriptionar;
@Size(max = 500)
@Column(name = "descriptionfr", length = 500)
private String descriptionfr;
@NotNull
@Column(name = "rating", nullable = false)
private Integer rating;
@ManyToMany(mappedBy = "indicators")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@JsonIgnoreProperties(value = { "indicators" }, allowSetters = true)
private Set<Competency> competencies = new HashSet<>();
// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return this.id;
}
public Indicator id(Long id) {
this.setId(id);
return this;
}
public void setId(Long id) {
this.id = id;
}
public Integer getCode() {
return this.code;
}
public Indicator code(Integer code) {
this.setCode(code);
return this;
}
public void setCode(Integer code) {
this.code = code;
}
public String getTitle() {
return this.title;
}
public Indicator title(String title) {
this.setTitle(title);
return this;
}
public void setTitle(String title) {
this.title = title;
}
public String getTitlear() {
return this.titlear;
}
public Indicator titlear(String titlear) {
this.setTitlear(titlear);
return this;
}
public void setTitlear(String titlear) {
this.titlear = titlear;
}
public String getTitlefr() {
return this.titlefr;
}
public Indicator titlefr(String titlefr) {
this.setTitlefr(titlefr);
return this;
}
public void setTitlefr(String titlefr) {
this.titlefr = titlefr;
}
public String getDescription() {
return this.description;
}
public Indicator description(String description) {
this.setDescription(description);
return this;
}
public void setDescription(String description) {
this.description = description;
}
public String getDescriptionar() {
return this.descriptionar;
}
public Indicator descriptionar(String descriptionar) {
this.setDescriptionar(descriptionar);
return this;
}
public void setDescriptionar(String descriptionar) {
this.descriptionar = descriptionar;
}
public String getDescriptionfr() {
return this.descriptionfr;
}
public Indicator descriptionfr(String descriptionfr) {
this.setDescriptionfr(descriptionfr);
return this;
}
public void setDescriptionfr(String descriptionfr) {
this.descriptionfr = descriptionfr;
}
public Integer getRating() {
return this.rating;
}
public Indicator rating(Integer rating) {
this.setRating(rating);
return this;
}
public void setRating(Integer rating) {
this.rating = rating;
}
public Set<Competency> getCompetencies() {
return this.competencies;
}
public void setCompetencies(Set<Competency> competencies) {
if (this.competencies != null) {
this.competencies.forEach(i -> i.removeIndicator(this));
}
if (competencies != null) {
competencies.forEach(i -> i.addIndicator(this));
}
this.competencies = competencies;
}
public Indicator competencies(Set<Competency> competencies) {
this.setCompetencies(competencies);
return this;
}
public Indicator addCompetency(Competency competency) {
this.competencies.add(competency);
competency.getIndicators().add(this);
return this;
}
public Indicator removeCompetency(Competency competency) {
this.competencies.remove(competency);
competency.getIndicators().remove(this);
return this;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Indicator)) {
return false;
}
return id != null && id.equals(((Indicator) o).id);
}
@Override
public int hashCode() {
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
return getClass().hashCode();
}
// prettier-ignore
@Override
public String toString() {
return "Indicator{" +
"id=" + getId() +
", code=" + getCode() +
", title='" + getTitle() + "'" +
", titlear='" + getTitlear() + "'" +
", titlefr='" + getTitlefr() + "'" +
", description='" + getDescription() + "'" +
", descriptionar='" + getDescriptionar() + "'" +
", descriptionfr='" + getDescriptionfr() + "'" +
", rating=" + getRating() +
"}";
}
}
as you can see I have extended the class and the extra fields do appear in the persitance of JPA but whenever I run the server my database is not updated with those fields.
the database is also postgres if that can help