У меня проблема. При попытке унаследовать от родительского класса атрибут, который не определен как идентификатор, но в моем дочернем классе да, возникает следующая ошибка:
MappingException: вы не можете переопределить [testDate] не- Свойство идентификатора из базового класса [com.test.BaseEntity] или @MappedSuperclass и сделать его идентификатором в подклассе [com.test.ChildEntity]!
Мой родительский класс:
import java.sql.Timestamp;
import java.time.Clock;
import java.time.Instant;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
@MappedSuperclass
public abstract class BaseEntity {
@Column(name = "CREATION_DATE_UTC")
protected Timestamp testDate;
public Timestamp getTestDate() {
return testDate;
}
public void setTestDate(Timestamp testDate) {
this.testDate = testDate;
}
@PrePersist
public void prePersist() {
testDate = Timestamp.from(Instant.now(Clock.systemUTC()));
}
}
Мой детский класс:
import java.io.Serializable;
import java.sql.Timestamp;
import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.gson.Gson;
@Entity(name = "CHILD")
@IdClass(ChildEntityPk.class)
public class ChildEntity extends BaseEntity implements Serializable {
private static final long serialVersionUID = 4392848588125748902L;
@Id
@Column(name = "CHILD_ID", insertable = false, updatable = false)
@JsonIgnore
private Integer id;
@Id
@Column(name = "CHILD_TEST_DATE", insertable = false, updatable = false)
@JsonIgnore
private Timestamp testDate;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Timestamp getTestDate() {
return testDate;
}
public void setTestDate(Timestamp testDate) {
this.testDate = testDate;
}
@Override
public String toString() {
return new Gson().toJson(this);
}
}