我有一个 Spring 项目,我使用 Spring Data REST 访问数据库(使用http://spring.io/guides/gs/accessing-data-rest/)
@RepositoryRestResource(collectionResourceRel = "test", path = "test")
public interface TestRepository extends PagingAndSortingRepository<Test, Long> {
@Query("SELECT max(p.lastUpdatedDate) FROM Test p")
Date findLastUpdatedDate();
}
当我尝试使用 URL localhost:8080/test/search/findLastUpdatedDate 访问上述方法以获取 MAX 日期时,出现错误
{"cause":null,"message":"Cannot create self link for class java.sql.Timestamp! No persistent entity found!"}
请建议我如何从测试表中获取最大 lastUpdatedDate。谢谢!
这是我的测试课:
@Entity
@Table(name="test")
public class Test implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String col1;
private String col2;
private String status;
@Column(name = "last_updated_date")
private Date lastUpdatedDate;
// getters, setters, hashcode, equals, toString methods are written
}