title: Hibernate Projections List
body: <p>I ned to get only a few column values from the table. So I have used Projections to achieve this. The code works, but I don't think it is effective. </p>
  
  <p>My issue was when I used ProjectionsList &amp; then set the criteria.list to an ArrayList - the Bulletin object is null. I'm not sure how to explain this better. So I will put the code and then please read below:</p>
  
  <pre><code> List&lt;Bulletin&gt; list = new ArrayList&lt;Bulletin&gt;();
   BulletinList bulletinList = null;
  
   Criteria criteria = null;
  
   criteria = this.getSession().createCriteria(Bulletin.class)
              .setProjection(Projections.projectionList()
              .add(Projections.property(bulletinIdAttr))
              .add(Projections.property(docNameAttr))   
              .add(Projections.property(docTypeCodeAttr))
              );        
      criteria.addOrder(Order.desc(createdTimeAttr));
  
      List&lt;Object&gt; rows = criteria.list();
      for (Object r : rows) {
          Object[] row = (Object[]) r;
          Bulletin bull = new Bulletin();
          bull.setBulletinId((Long) row[0]);
          bull.setDocumentName((String) row[1]);
          bull.setDocumentTypeCode((String) row[2]);
          list.add(bull);
        }
  
      bulletinList = new BulletinList();
      bulletinList.setBulletins(list);
  
      return bulletinList;
  </code></pre>
  
  <p>I just need to set criteria.list to BulletinList (Class that holds a list of Bulletin objects). But when I use projections, Bulletin object is null.</p>
  
  <p>I also was reading another thread to use </p>
  
  <pre><code>setResultTransformer(Transformers.aliasToBean
  </code></pre>
  
  <p>But that ain't working either. So can someone help in this on how to make the code better.</p>
  
  <p>Thanks</p>
  
  <p>Harish </p>