简体   繁体   中英

Java Spring Boot/Mysql - Doing a query with a HashSet as a Parameter

I'm doing a Spring Boot application with JPA and I have and object (let's call it Conversation ) which has a property that is a HashSet of another object ( User ). In the ConversationRepository there's the following method:

@Query("SELECT c FROM Conversation c WHERE ?1 MEMBER OF c.users
Conversation findByUsers(Set<User> users);

However, when I try to use this query passing a HashSet of User as parameter (which it has two users stored), there's a SQLException (1241) which says that the operand should contain 2 columns.

What is the correct way to do a query with a HashSet as a parameter?

Your method is not passing the first parameter value. Your query expecting two inputs and your method signature has only one. try passing the value for ?1.

Modify your query like

@Query("SELECT c FROM Conversation c WHERE :value MEMBER OF c.users

Conversation findByUsers(User value, Set users);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM