私はSpring JPAが初めてです。Product という名前のモデルがあります。products テーブルの最近のレコードを取得するための API エンドポイントを作成しようとしています。
public static interface Repository extends PagingAndSortingRepository<Product, Long>
{
List findTop2ByOrderByIdDesc();
}
アプリケーション HAL Browser http://localhost:8080/api/v1/products/search/findTop2ByOrderByIdDesc を実行すると
次のようなエラーが表示されます
{
"timestamp": 1440573947629,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.dao.IncorrectResultSizeDataAccessException",
"message": "result returns more than one elements; nested exception is javax.persistence.NonUniqueResultException: result returns more than one elements",
"path": "/api/v1/products/search/findTop2ByOrderByIdDesc"
}
これを修正する方法。親切なアドバイス