データアクセスレイヤーとしてSpring
とJpaRepository
を使用しています。私は以下のように私の@Repository
インタフェースを持っている:春JpaSpecificationExecutor新しいクエリメソッドNoSuchElementException
@Repository
interface EventRepository extends JpaRepository<Event, Long>, JpaSpecificationExecutor<Event> {
.... some custom methods irrelevant to this post ....
}
は、ここに私の単純化モデルクラスです:私はそこJpaSpecificationExecutor
を使用してい
class Event {
Long eventID;
String name;
Date time;
Zone zone;
}
class Zone {
Long zoneId;
String zoneName;
User user;
}
class User {
Long userId;
String username;
}
特定time
でEvent
秒のリストについては、データベースをフェッチします。私は、このメソッドを使用していますし、それが正常に動作:
Page<T> findAll(Specification<T> spec, Pageable pageable);
しかし、私は、特定のUser
のエントリを取得するために、別の条件を追加します。
私はこのような新しいメソッドを作成してみました:
Page<Event> findAllByZone_User(User user, Specification<Event> spec, Pageable pageable);
をしかし、私はそれを呼び出すときに、私はこの行例外で取得:
java.util.NoSuchElementException: null
は、このようなメソッドを作成することも可能ですか?そうでない場合はどうすればいいですか?
あなたはfindByZoneUser(ユーザーユーザー) 'Specification'と' Pageable'について – Barath
@barathが、何をしようとすることはできますか? – user3626048
あなたはまた、私のリポジトリとコントローラ 'ページの小さな変化 findAllByZoneUserUserId(ロングのuserId、Pageableの後に同じ結果を得ることができます' findAllByZone_User' –
CIPHER007