title: How to use bitwise operators in JPA CriteriaBuilder
body: <p>I am using JPA CriteriaBuilder, and List for querying user table. I need to use bitwise &amp; operator in CriteriaBuilder. My sample code base is as follows. </p>
  
  <p>User table structure is as follows. </p>
  
  <pre><code>create TABLE `tbl_user` (
      `id` BIGINT NOT NULL AUTO_INCREMENT,
      `login_id` VARCHAR(255) NOT NULL,
      `name` VARCHAR(255) NOT NULL,
      `email` VARCHAR(500) NOT NULL,
      `role_value` INTEGER,
      `password` VARCHAR(255) NOT NULL,
      PRIMARY KEY (`id`)
  );
  </code></pre>
  
  <p>Here <code>role_value</code> is the field where we are specifying bitwise OR values to keep the role of the user. </p>
  
  <p>Roles are specified with below bit values</p>
  
  <pre><code>public enum Role {
  
      ROLE_POLICE(1, "POLICE"),
      ROLE_BRIDGE(2, "BRIDGE"),
  
      ROLE_SECURITY(4, "SECURITY"),
      ROLE_ASSISTANT_USER(8, "ASSISTANT_USER"),
      ROLE_HARDWARE_USER(16, "HARDWARE_USER"),
      ;
  
      private final String roleValue;
      private final Integer id;
  
      Role(Integer id, String roleValue, Role... secondaryRoles) {
          this.id = id;
          this.roleValue = roleValue;
          this.secondaryRoles = secondaryRoles;
      }
  
  }
  </code></pre>
  
  <p>I would like to query user list using CriteriaBuilder, where i need to filter users with certain roleValues using "Predicate" and JPA "Expressions".</p>
  
  <p>My code is as follows. </p>
  
  <pre><code>@Override
  public Page&lt;UserView&gt; listUsers(UserListRequest userListRequest) {
  
  
      CriteriaBuilder cb = entityManager.getCriteriaBuilder();
      CriteriaQuery&lt;User&gt; listCriteria = cb.createQuery(User.class);
      Root&lt;User&gt; userRoot = listCriteria.from(User.class);
  
      if (!userListRequest.getUserIds().isEmpty()) {
          wherePredicates.add(cb.in(userRoot.get("id")).value(userListRequest.getUserIds()));
      }
  
      /* this portion is having syntax error */
      if (null != userListRequest.getRoleValue()) {
          wherePredicates.add(cb.equal(userRoot.get("role_value"), (userRoot.get("role_value") &amp; userListRequest.getRoleValue()));
      }   
  
      .
      .
      .
      return getPageFromTypedQuery(cb, userRoot, listCriteria, wherePredicates, userListRequest, UserView.class);
  }
  </code></pre>