0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Spring boot select文

Posted at

Repositoryでselect文を書きし実行すると、以下のエラーが出ました。

defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.List com.example.demo

@Query(value="select * from userInfo LEFT JOIN bookInfo on userInfo.userId = bookInfo.userId")

なんやねん!といろいろ調べると、、、

前提知識として、@Queryとアノテーションをつけてあげるとメソッド命名規則からクエリを定義せず、SQL文を直で書くことができます。
ですが、普通にSQL文を書くだけではうまく読み込んでくれないみたいです。

解決策として、コードに末尾にnativeQuery = trueを追加してあげるとちゃんと動いてくれました。

@Query(value="select * from userInfo LEFT JOIN bookInfo on userInfo.userId = bookInfo.userId", nativeQuery = true)

無事解決!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?