我会为每个类/实体使用带有 ID 和时间戳的 ModelBase。但是当我Long
在界面中使用主键的类型时,JPARepository<>
我会收到消息
Not an entity: class java.lang.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();
}
}
从 Modelbase 继承的 Modelclass
@Entity
@Table(name = "Name")
public class Name extends ModelBase implements Serializable {}
回购
public interface NameRepository extends JpaRepository<Long, Name>{}
我究竟做错了什么?
谢谢