0

Spring Data REST を使用してデータベースにアクセスする Spring プロジェクトがあります ( 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!"}

Test テーブルから最大 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
}
4

1 に答える 1

0

日付には @Temporal アノテーションを使用する必要があります。

また、java.sql.Timestamp の代わりに java.util.Date または Joda time を使用する必要があります。

Spring Data JPA には、作成/変更されたタイムスタンプも組み込まれているため、それを調べる必要があります。

http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#auditing

于 2014-12-02T21:28:15.790 に答える