title: Hibernate Query By Example and Projections
body: <p>To make it short: hibernate doesn't support projections and query by example? I found this post:</p>
  
  <p>The code is this:</p>
  
  <pre><code>User usr = new User();
  usr.setCity = 'TEST';
  getCurrentSession().createCriteria(User.class)
  .setProjection( Projections.distinct( Projections.projectionList()
  .add( Projections.property("name"), "name")
  .add( Projections.property("city"), "city")))
  .add( Example.create(usr))
  </code></pre>
  
  <p>Like the other poster said, The generated sql keeps having a where class refering to just <strong>y0_= ? instead of this_.city</strong>. </p>
  
  <p>I already tried several approaches, and searched the issue tracker but found nothing about this.</p>
  
  <p>I even tried to use Projection alias and Transformers, but it does not work:</p>
  
  <pre><code>User usr = new User();
  usr.setCity = 'TEST';
  getCurrentSession().createCriteria(User.class)
  .setProjection( Projections.distinct( Projections.projectionList()
  .add( Projections.property("name"), "name")
  .add( Projections.property("city"), "city")))
  .add( Example.create(usr)).setResultTransformer(Transformers.aliasToBean(User.class));
  </code></pre>
  
  <p>Has anyone used projections and query by example ?</p>