title: Why Hibernate inlines Integer parameter list passed to JPA Criteria Query?
body: <p>I am building a query using JPA Criteria API. When I created two restriction predicates using <code>javax.persistence.criteria.Path#in(Collection&lt;?&gt;)</code> method the generated SQL query was a little bit different than I excpected. </p>
  
  <p>The first predicate which was build over <code>int</code> attribute produced SQL with all elements of parameter collection inlined: <code>in (10, 20, 30)</code>.</p>
  
  <p>The second predicate which was build over <code>String</code> attribute produced parametrized SQL: <code>in (?, ?, ?)</code>.</p>
  
  <p>Let me show:</p>
  
  <p>Entity:</p>
  
  <pre><code>@Entity
  public class A {
      @Id 
      private Integer id;
      private int intAttr;
      private String stringAttr;
      //getter/setters
  }
  </code></pre>
  
  <p>Query: </p>
  
  <pre><code>CriteriaBuilder cb = entityManager.getCriteriaBuilder();
  CriteriaQuery&lt;A&gt; q = cb.createQuery(A.class);
  Root&lt;A&gt; root = q.from(A.class);
  q.where(
      root.get("intAttr").in(Arrays.asList(10, 20, 30)),
      root.get("stringAttr").in(Arrays.asList("a", "b", "c"))
  );
  entityManager.createQuery(q).getResultList();
  </code></pre>
  
  <p>Log:</p>
  
  <pre><code>select
      a0_.id as id1_0_,
      a0_.intAttr as intAttr2_0_,
      a0_.stringAttr as stringAt3_0_ 
  from
      A a0_ 
  where
      (
          a0_.intAttr in (
              10 , 20 , 30
          )
      ) 
      and (
          a0_.stringAttr in (
              ? , ? , ?
          )
      ) 
  org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [VARCHAR] - [a] 
  org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [2] as [VARCHAR] - [b] 
  org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [3] as [VARCHAR] - [c] 
  </code></pre>
  
  <p>My questions:</p>
  
  <ol>
  <li>Why are elements of Integer list inlined directly to sql and elements of String list are handled as prepared statement parameters?</li>
  <li>Is this feature Hibernate specific or is it guaranteed by JPA?</li>
  <li>From DB perspective which of two should be preferred?</li>
  <li>Is this int-yes string-no inlining somehow related to sql injection?</li>
  <li>Is this somehow related to limitation of number of values in sql IN clause the RDMBS can process?</li>
  <li>How to write a criteria query which will handle Integer parameter list the same way as String parameter list.</li>
  </ol>