title: How to fetch entities by objects value in JPA criteria api query
body: <p>I am using JPA with JSF datatable with lazy loading.
  Here One car can be owned by many users. So when i logged in to the application i want the cars which is owned by the user logged in(assume it as userId=1).
  I have a mapping table "Cars_User" that contains carId and userId columns. 
  My Entities are like this
  My Car Class</p>
  
  <pre><code>@Entity
  @Table(name="car")
  public class Car implements Serializable {
   private static final long serialVersionUID = 1L;
  
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private String id;
  
   @Transient
   private boolean myCar;
  
   @NotNull
   @Size(min = 1, max = 50)
   public String name;
  
   @OneToMany(cascade = { CascadeType.REFRESH }, fetch = FetchType.LAZY, orphanRemoval = true)
   @JoinTable(name = "Cars_User", joinColumns = @JoinColumn(name = "carId"), inverseJoinColumns = @JoinColumn(name = "userId"))
   private List&lt;User&gt; carUsers = new ArrayList&lt;User&gt;();
  
   getters ...
  
   setters ...
  }
  </code></pre>
  
  <p>User Class</p>
  
  <pre><code>@Entity(name = "User")
  public class User implements Serializable {
  
     private static final long serialVersionUID = 1L;
  
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     private int id;
  
     private String firstName;
  
     private String lastName;
  }
  </code></pre>
  
  <p>I have found one answer for Lists of String collection in this <a href="https://stackoverflow.com/a/10716711/4858893">link</a> but how can be achieved in my case.
  I wanted to do get all Cars entities in criteria api that contains the logged in user id "userId" in carUsers Lists. can anyone please help?</p>