title: Simple CriteriaQuery in JPA Criteria API that is too much for a noob
body: <p>I am trying to write following SQL query using JPA Criteria API</p>
  
  <pre><code>SELECT * FROM roles WHERE roles.name IN (SELECT users.role FROM users where name="somename");
  </code></pre>
  
  <p>and it is a bit to much for me (I have just started learing Criteria API). I got something like this:</p>
  
  <pre><code>    CriteriaBuilder criteriaBuilder = manager.getCriteriaBuilder();
      CriteriaQuery&lt;RoleEntity&gt; criteriaQuery = criteriaBuilder.createQuery(RoleEntity.class);
      Root&lt;RoleEntity&gt; root = criteriaQuery.from(RoleEntity.class);
  
      Subquery&lt;UserEntity&gt; subquery = criteriaQuery.subquery(UserEntity.class);
      Root&lt;UserEntity&gt; subqueryRoot = subquery.from(UserEntity.class);
      subquery.where(criteriaBuilder.equal(subqueryRoot.get(UserEntity_.username), username));
      subquery.select(subqueryRoot);
  </code></pre>
  
  <p>And I have no idea how to put it all together.</p>
  
  <p>Best regards,
  Bartek</p>