title: Hibernate sticking NULL values into list
body: <p>I have inherited a bit of Java code that uses Hibernate.  Some of the people using this code are now reporting that they are getting NullPointerExceptions all over the place.  </p>
  
  <p>I've been able to track this down and found that when we execute a query that pulls a list of objects from the database, that has a list of objects (that get pulled from a different table) Hibernate seems to be leaving holes in the list (NULL values).  So the list may look something like:</p>
  
  <pre><code>Object
  Object
  NULL
  Object
  </code></pre>
  
  <p>The code we are using to pull the information out of the database is:</p>
  
  <pre><code>List&lt;PrinterGroup&gt; groups = 
      this.getSession().createQuery( "from PrinterGroup" ).list();
  </code></pre>
  
  <p>And then inside each PrinterGroup is a list of Filters that have the NULL values in them.</p>
  
  <p>While I could go around and find every instance were we loop over this list and add a NULL check I feel it is a bandaid fix, and there has to be a way to tell Hibernate to not pull null values in.</p>
  
  <p>EDIT:</p>
  
  <ul>
  <li>We are using Hibernate 3.2.2</li>
  </ul>
  
  <p>EDIT2:</p>
  
  <p>So the database seemed to be confusing.  The PrinterGroup -> Filter relationship is a one to many relationship.  So PrinterGroups have a list of filters.  The problem is that list of filters has null values in it when it comes out of the database (There are no null values in the database by the way) and the list comes out looking like above.</p>
  
  <p>EDIT3:</p>
  
  <p>Here is the mapping relavant picese in the PrinterGroup HBM</p>
  
  <pre><code>&lt;subclass name="PrinterGroup" discriminator-value="PG"&gt;
     &lt;list name="filters"
                lazy="true"
                table="PG_FILTER"
                 inverse="false"
                  cascade="all-delete-orphan"&gt;
  
          &lt;key&gt;
             &lt;column name="PG_ID" not-null="false"/&gt;
          &lt;/key&gt;
          &lt;index column="LISTPOSITION"/&gt;
          &lt;one-to-many class="Filter"/&gt;
       &lt;/list&gt;
  </code></pre>
  
  <p>And the Filter is a pretty basic POJO mapping.</p>