title: When using Hibernate for Java getting abnormal behavior binding parameterList in HQL
body: <p><strong>UPDATE</strong>
  I found the issue. Kind of embarrassing. The client side code was sending a <code>Set</code> of 1 element which was the concatenated String of the report Ids. AArgh!</p>
  
  <hr>
  
  <p>I am using hibernate v3.6.4 in my Java project. I am getting problems when trying to use a parameter list for a named parameter in my HQL query. </p>
  
  <p>Basically I want to get all the records which match one of the "<code>id</code>"s mentioned in the <code>IN</code> clause.</p>
  
  <p>I tried using both HQL &amp; Criteria I get the same result. </p>
  
  <p>My HQL query,</p>
  
  <pre><code>Set&lt;String&gt; reportIds = new HashSet&lt;String&gt;();
  reportIds.add("1");
  reportIds.add("2");
  
  String whereClause = "from Report where id IN (:reportIds) ";
  Query query = session.createQuery(whereClause);
  query.setParameterList("reportIds", reportIds);
  </code></pre>
  
  <p>Output = empty list. Although I checked by firing manual sql queries in the terminal that there are indeed such records.</p>
  
  <p>I turned on the logging and here is what I see,</p>
  
  <pre><code>Hibernate: 
      /* 
  from
      Report 
  where
      id IN (
          :ids
      ) */ select
          mediavalue0_.id as id31_,
          ...
  
      from
          report mediavalue0_ 
      where
          mediavalue0_.id in (
              ?
          )
  HibernateLog --&gt; 13:22:36 TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [VARCHAR] - 1,2
  </code></pre>
  
  <p>This is very abnormal because if you notice the final bind statement it considers the toString of the Set! i.e. "1,2" instead of "1" and then "2"!</p>
  
  <p>I was messing around with it so on a whim I decided to directly create the instance of the set inside the <code>setParameterList</code> method call itself. Like so,</p>
  
  <pre><code>query.setParameterList("reportIds", Sets.newHashSet("1","2"));
  </code></pre>
  
  <p>And it worked! BTW Sets.newHashSet is a construct provided google's guava library. I use the same library to generate the original reportIds set. So there is no inconsistency there.</p>
  
  <p>This query translates to following TRACE,</p>
  
  <pre><code>from
      Report 
  where
      id IN (
          :ids
      ) */ select
          mediavalue0_.id as id31_,
          ...
      from
          report mediavalue0_ 
      where
          mediavalue0_.id in (
              ? , ?
          )
  HibernateLog --&gt; 13:28:57 TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [VARCHAR] - 1
  HibernateLog --&gt; 13:28:57 TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [2] as [VARCHAR] - 2
  </code></pre>
  
  <p>Notice the separate binds for VARCHAR.</p>
  
  <p>I am totally flummoxed by this odd behavior. Maybe some of you guys can point out what I am doing wrong.</p>
  
  <p>FYI the criteria construct I used (&amp; which resulted in the same output) is like so,</p>
  
  <pre><code>Criteria criteria = session.createCriteria(Report.class);
  criteria.add(Restrictions.in("id", reportIds));
  </code></pre>
  
  <p>P.S. I also used a named sql query with same result</p>
  
  <pre><code>&lt;sql-query name="reportByIds"&gt;
      &lt;return class="report.Report"/&gt;
      SELECT mvr.* from report mvr
      WHERE mvr.id IN :ids
  &lt;/sql-query&gt;  
  </code></pre>