我有以下实体映射:
@Entity
@Table(name = "books")
public class Book implements Serializable {
@ManyToMany
@JoinTable(name="books2categories",joinColumns=@JoinColumn(name="book_id"),inverseJoinColumns=@JoinColumn(name="category_id"))
Collection
…
@Entity
@Table(name = "categories")
public class Category implements Serializable {
@ManyToMany(mappedBy="categories")
private Collection
看了BookRepository接口:
public interface BookRepository extends JpaRepository
如果我在查询本身错了,请修复我.
当我为findByCategories方法运行测试时,我收到错误:
testFindByCategories(com.savdev.springmvcexample.repository.JpaBookRepositoryTest):
org.hibernate.QueryParameterException: Position beyond number of
declared ordinal parameters. Remember that ordinal parameters are
1-based! Position: 1; nested exception is
java.lang.IllegalArgumentException:
org.hibernate.QueryParameterException: Position beyond number of
declared ordinal parameters. Remember that ordinal parameters are
1-based! Position: 1
我有哪个选项可以解决它?
第二,我可以调试将参数传递给查询的Spring Data Jpa逻辑吗?
我得到了Spring Data Jpa返回的代理,无法理解在哪里使用断点来调试这种行为.
更新:
我用(?1)修复了它:
@Query("SELECT b FROM Book b INNER JOIN b.categories c WHERE c IN (?1)")
代替
@Query("SELECT b FROM Book b INNER JOIN b.categories c WHERE c IN (:categories)")
最佳答案
原文链接:https://www.f2er.com/spring/431868.html