title: IN and = operator in JPA query language
body: <p>I have a problem regarding jpa query. 
  There are two tables i.e. Post table and Tag table
  There is many to many relationship between Post and Tag</p>
  
  <p>Now I want to write a query such that when multiple tags are chosen then all the posts associated with those tags should be selected.
  For example, </p>
  
  <pre><code>post1 has tags friends and motivation
  post2 has tags motivation and pune
  post3 has tag boxing
  </code></pre>
  
  <p>if tags friends and pune are chosen then post1 and post 2 should be retrieved
  if tag boxing is chosen then only post 3 should be retrieved
  if tags boxing and motivation are chosen then all three posts should be retrieved.</p>
  
  <p>I tried following things</p>
  
  <pre><code>SELECT DISTINCT p FROM Post p JOIN p.tags tags WHERE p.tags IN :tags
  </code></pre>
  
  <p>but it gives validator error that</p>
  
  <pre><code>The state field path 'p.tags' cannot be resolved to a collection type.
  </code></pre>
  
  <p>If I try like this </p>
  
  <pre><code>SELECT DISTINCT p FROM Post p JOIN p.tags tags WHERE p.tags = :tags
  </code></pre>
  
  <p>then it complies fine but after passing a list of tags it gives error</p>
  
  <pre><code> java.lang.IllegalArgumentException: You have attempted to set a value of type class java.util.ArrayList for parameter tags with expected type of class com.justme.model.entities.Tag from query string SELECT DISTINCT p FROM Post p JOIN p.tags tags WHERE p.tags = :tags.
  </code></pre>
  
  <p>Thank you for reading this much :) can you please guide me on this?</p>
  
  <p>how can I achieve the results mentioned above?
  my persistence provider is eclipseLink</p>
  
  <p>This is Post entity </p>
  
  <pre><code>@Entity
  @NamedQueries({
      @NamedQuery(name = "Post.selectAllPosts", query = "SELECT p FROM Post p ORDER BY p.dateCreated DESC"),
      @NamedQuery(name = "Post.selectPostForUser", query = "SELECT p FROM Post p WHERE p.user = :user ORDER BY p.dateCreated DESC"),
      @NamedQuery(name = "Post.selectPostsByTags", query = "SELECT DISTINCT p FROM Post p JOIN p.tags tags WHERE p.tags IN :tags") })
  public class Post implements Serializable {
  private static final long serialVersionUID = 1L;
  
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private int idpost;
  
  @Lob
  private String content;
  
  private String title;
  
  // bi-directional many-to-one association to User
  @ManyToOne(cascade = CascadeType.PERSIST)
  @JoinColumn(name = "iduser")
  private User user;
  
  // bi-directional many-to-many association to Tag
  @ManyToMany(cascade = CascadeType.PERSIST)
  @JoinTable(name = "post_tag", joinColumns = @JoinColumn(name = "idpost"),         inverseJoinColumns = @JoinColumn(name = "idtag"))
  private List&lt;Tag&gt; tags = new ArrayList&lt;Tag&gt;();
  
  @Temporal(TemporalType.DATE)
  private Date date = null;
  @Temporal(TemporalType.TIMESTAMP)
  private Date dateCreated = new Date();
  
  public Post() {
  }
  
  public int getIdpost() {
      return this.idpost;
  }
  
  public void setIdpost(int idpost) {
      this.idpost = idpost;
  }
  
  public String getContent() {
      return this.content;
  }
  
  public void setContent(String content) {
      this.content = content;
  }
  
  public String getTitle() {
      return this.title;
  }
  
  public void setTitle(String title) {
      this.title = title;
  }
  
  public User getUser() {
      return this.user;
  }
  
  public void setUser(User user) {
      this.user = user;
  }
  
  public List&lt;Tag&gt; getTags() {
      return this.tags;
  }
  
  public void setTags(List&lt;Tag&gt; tags) {
      this.tags = tags;
  }
  
  public Date getDate() {
      return date;
  }
  
  public void setDate(Date date) {
      this.date = date;
  }
  
  public Date getDateCreated() {
      return dateCreated;
  }
  
  public void setDateCreated(Date dateCreated) {
      this.dateCreated = dateCreated;
  }
  
  @Override
  public String toString() {
      return "Post [idpost=" + idpost + ", content=" + content + ", title="
              + title + ", date=" + date + "]";
  }
  
  }
  </code></pre>
  
  <p>This is Tag Entity</p>
  
  <pre><code>@Entity
  @NamedQueries({
      @NamedQuery(name = "Tag.selectTags", query = "SELECT tag FROM Tag tag WHERE tag.tagName LIKE :keyword"),
      @NamedQuery(name = "Tag.selectMatchingTags", query = "SELECT t.tagName FROM Tag t WHERE t.tagName LIKE :keyword"),
      @NamedQuery(name = "Tag.selectTagByName", query = "SELECT tag FROM Tag tag WHERE tag.tagName = :tagName"),
      @NamedQuery(name = "Tag.selectTagsForAllPosts", query = "SELECT DISTINCT tag FROM Tag tag, Post post JOIN tag.posts posts WHERE post.user = :user")})
  
  public class Tag implements Serializable {
  private static final long serialVersionUID = 1L;
  
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private int idtag;
  
  private String tagName;
  
  // bi-directional many-to-many association to Post
  @ManyToMany(mappedBy = "tags", cascade = CascadeType.PERSIST)
  private List&lt;Post&gt; posts;
  
  
  public Tag() {
  
  }
  
  public Tag(String tagName) {
      this.tagName = tagName;
  }
  
  
  public int getIdtag() {
      return this.idtag;
  }
  
  public void setIdtag(int idtag) {
      this.idtag = idtag;
  }
  
  public String getTagName() {
      return this.tagName;
  }
  
  public void setTagName(String tagName) {
      this.tagName = tagName;
  }
  
  public List&lt;Post&gt; getPosts() {
      return this.posts;
  }
  
  public void setPosts(List&lt;Post&gt; posts) {
      this.posts = posts;
  }
  
  @Override
  public String toString() {
      return tagName;
  }
  
  }
  </code></pre>