Good day! There are two entities, for example, the user and documents related many to many. I want to select all documents, the current user (through the object does not suit, because there are additional parameters such as type, status ...). I can not understand how to correctly write a request. I use Spring Data.
@Query("select c from Doc c , User u where c.type=:type and u.id = :userId and c.status =:statusId") List<Edoc> findAllByUserAndType (@Param("type") int type,@Param("userId") long userId ,@Param("statusId") int statusId ); The first entity:
public class Edoc { @ManyToMany @JoinTable(name = "Edocs_users", schema = "edocs", joinColumns = @JoinColumn(name = "edoc_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id")) private Set<User> users = new HashSet<User>(); } The second entity:
public class User { @ManyToMany(mappedBy = "users" ,fetch = FetchType.EAGER) private Set<Edoc> edocs = new HashSet<Edoc>(); }