我有一个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,访问上面的方法来获取最大日期时,我得到了错误
{"cause":null,"message":"Cannot create self link for class java.sql.Timestamp! No persistent entity found!"}请建议如何从测试表中获取最大lastUpdatedDate。谢谢!
下面是我的Test类:
@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
}发布于 2014-12-03 05:28:16
您需要在日期上使用@Temporal注释。
您还应该使用java.util.Date或Joda time而不是java.sql.Timestamp
Spring Data JPA也有内置的创建/修改时间戳,因此您应该研究一下:
http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#auditing
https://stackoverflow.com/questions/27256099
复制相似问题