0
我会为每个类/实体使用带有ID和时间戳的ModelBase。但是,当我的用户在JPARepository<>
界面我得到的消息Modelbase(继承)Spring Data JPA
Not an entity: class java.lang.Long
守则Long
类型的主键:
@MappedSuperclass
public class ModelBase implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable = false, columnDefinition = "datetime")
private Date lastModified;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getLastModified() {
return lastModified;
}
public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}
@PreUpdate
@PrePersist
public void updateLastModified() {
lastModified = new Date();
}
}
Modelclass从模型库 inheritanced
@Entity
@Table(name = "Name")
public class Name extends ModelBase implements Serializable {}
回购
public interface NameRepository extends JpaRepository<Long, Name>{}
我做错了什么?
感谢
这真的很尴尬,谢谢。 – KenavR
没问题!不要忘记接受答案:) – Luciano
我会,需要等10分钟。 – KenavR