내 최대 절전 모드 엔티티에 대한 기본 클래스의 몇 가지있다 :MappedSuperClasses에서 속성 값을 무시하고 최대 절전 모드로 전환 하시겠습니까?
이@MappedSuperclass
public abstract class Entity<T> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private T id;
public T getId() { return this.id; }
}
@MappedSuperclass
public abstract class TimestampedEntity<T> extends Entity<T> {
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "created_at")
private Date createdAt;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "updated_at")
private Date updatedAt;
// Getters and setters for createdAt and updatedAt....
}
각 엔티티 클래스 분명히 이러한 기본 클래스를 확장하고 ID 속성과 createdAt 및 updatedAt 특성을 얻을 수 ...
@Entity
public class SomeEntity extends TimestampedEntity<Long> {
// Insert SomeEntity's fields/getters/setters here. Nothing out of the ordinary.
}
내 문제는 SomeEntity의 새로운 인스턴스를 저장할 때 Hibernate가 수퍼 클래스에서 속성 값을 무시하고 있다는 것이다. id 열 (테이블의 ID 열과 동기화되지 않음)에 대한 자체 값을 삽입하려고 시도하고 이 확실히으로 설정 되었더라도 createdAt 및 updatedAt에 대해 null을 삽입하려고 시도합니다.
SomeEntity e = new SomeEntity(/* ... */);
e.setCreatedAt(new Date());
e.setUpdatedAt(new Date());
// Here Hibernate runs an INSERT statement with nulls for both createdAt and updatedAt
// as well as a wildly out of sequence value for id
// I don't think it should be trying to insert id at all, since the GenerationType is IDENTITY
Long id = (Long)session.save(e);
여기서 내가 뭘 잘못하고 있니? 어떻게하면 Hibernate가 MappedSuperclasses로부터 프로퍼티 값을 가져 오게 할 수 있습니까?