如何使用JPA和Spring从列表中找到具有字段的不同行?

27 浏览
0 Comments

如何使用JPA和Spring从列表中找到具有字段的不同行?

我正在使用Spring来连接数据库。我有一个继承了CrudRepository的接口。这是我想在数据库上执行的查询:SELECT DISTINCT name FROM people WHERE name NOT IN UserInputSet。我希望能够在不使用任何SQL注解的情况下完成,所以如果没有NOT也可以。

有没有办法可以做到这一点?我查看了Spring文档,但是没有找到任何相关信息(http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation


这是我尝试过的但是不起作用的代码。

@Query("SELECT DISTINCT name FROM people WHERE name NOT IN (?1)")
List findNonReferencedNames(List names);

这是我得到的异常:

Error creating bean with name 'peopleRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List de.test.tasks.persistence.PeopleRepository.findNonReferencedNames(java.util.List)!
Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: people is not mapped [SELECT name FROM people WHERE name NOT IN (?1)]

0