LoginSignup
0
0

More than 3 years have passed since last update.

Spring Data JPAの非named queryなのでNo property list found for type

Posted at

以下のように、named queryではないのにうっかりnameにJPQLを指定しまうと、一見不可解な実行時エラーが発生する。

@Repository
public interface SampleRepository extends JpaRepository<Sample, Long> {
    @Query(name = "select s from Sample s")
    List<Sample> list();
}
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property list found for type Sample!
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:94) ~[spring-data-commons-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:382) ~[spring-data-commons-2.3.3.RELEASE.jar:2.3.3.RELEASE]
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:358) ~[spring-data-commons-2.3.3.RELEASE.jar:2.3.3.RELEASE]

落ち着いてみれば、単にそんなnameのnamed queryは無いですよ、というエラーなのだが、正しくJPQLを指定してるつもりなのに実行時エラーになって焦ってしまった……のでメモを残しておく。

正しくはvalueにJPQLを指定すればよい。

    @Query("select s from Sample s")
    List<Sample> list();
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0