With this request:

@Entity @Table(name="users") public class User implements UserDetails,Serializable{ @ManyToMany(mappedBy="recipients") private List<Project>recipientsProjects = new ArrayList<>(); } @Entity @Table(name="projects") public class Project implements Serializable{ @Id @Expose @GeneratedValue private long id; @Expose private String name; @ManyToMany @Expose(serialize=false) @JoinTable(name = "project_recipient",schema="post", joinColumns = {@JoinColumn(name = "project_id",referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "user_id",referencedColumnName = "id")}) private List<User>recipients = new ArrayList<>(); } mySql = "SELECT u FROM User u join "; mySql+= "u.recipientsProjects r WHERE r.name NOT LIKE :project"; query = em.createQuery(mySql); query.setParameter("project", project.getName()); List<User>users = query.getResultList(); 

still displays the user with such a project. Please tell me how to make a request. Thank.

  • Some kind of weird request. In the list of fields indicated alias table. Not a table joins, but a field of this table. This request cannot be executed - Anton Shchyrov
  • @AntonShchyrov added field description in Entity - Nikolay Egorov
  • Judging by the text of the query SELECT u FROM User u join u.recipientsProjects r WHERE r.name NOT LIKE: project . there is a database with the name u, in which there is a table recipientsProjects, in which there is a field name, and the current database (possibly the same), in which there is a table User, in which there is a field u. It is right? - Akina
  • @Akina is a company (project) in a company there are people (users); the company has a name (name). ManyToMany's connection for user List <Project> is recipientsProjects, and for project List <User> recipients. You need to select all artists who are not in the project with the name ": project". - Nikolay Egorov
  • Better add to the question the DDL of all the tables. And in the same place in the question describe all these links, if they are not organized using FK. - Akina

0