【问题标题】:JPQL @Query - Could not prepare statement exceptionJPQL @Query - 无法准备语句异常
【发布时间】:2021-11-07 13:59:35
【问题描述】:

当我尝试执行这个 JPQL 时:

@Query("SELECT COUNT(v) FROM Vote v JOIN FETCH Restaurant WHERE v.restaurant.id=?1" )
Integer getVoteCountByRestaurantId(int id);

我有这个例外

nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement"

我试着改成

@Query("SELECT COUNT(v.id) FROM Vote v JOIN FETCH Restaurant WHERE v.restaurant.id=?1" )

但例外是一样的,我做错了什么?

【问题讨论】:

  • 你在使用什么底层rdbms
  • @Mureinik H2 数据库

标签: java jpa jpql


【解决方案1】:

试试这个:

@Query("SELECT COUNT(v.id) FROM Vote v JOIN v.restaurant r WHERE r.id=?1" )

【讨论】:

  • Exception mow is: query specified join fetching, but the owner of the fetched association is not present in the select list ;(
  • 你能用join代替join fetch吗?
猜你喜欢
  • 2013-12-24
  • 2019-03-15
  • 1970-01-01
  • 1970-01-01
  • 2015-08-25
  • 1970-01-01
  • 2017-04-12
  • 1970-01-01
  • 2021-02-01
相关资源
最近更新 更多