title: Loading millions of DB row in wicket table through a list causing outofmemory error
body: <p>I'm loading million lines of data by sortabledataprovider 
  .. the query returns a list(Arraylist) as I sent it to a Wicket ajax enabled table and pagination enable table. 
  So the problem is that - If there are concurrent queries - the application might get crashed.
  I'm already getting Java heap space error with just 100,000 rows in DB. 
  <strong>So what I want  to  achieve is this - when a user click on next page or may be number 10th page - it will load only the number 10th pages data from the DB - not the whole query which might have million lines in it.</strong> </p>
  
  <p>here is how I loading the list by query </p>
  
  <pre><code>      final SyslogProvider&lt;SyslogParsed&gt; sysLogProviderAjax = new SyslogProvider&lt;SyslogParsed&gt;(new ArrayList&lt;SyslogParsed&gt;());
  
       *
       *
             daoList = syslogParsedDao.findByDatesAndHostName(utcStartDate, utcEndDate, null);
          sysLogProviderAjax.setList(daoList);
  </code></pre>
  
  <h1>       **</h1>
  
  <p>DB query returning the big list of all rows </p>
  
  <pre><code>           public List&lt;logParsed&gt; findByDatesAndHostName() {
      return getJpaTemplate().execute(new JpaCallback&lt;List&lt;SyslogParsed&gt;&gt;() {
  
              return query.getResultList();
          }
      });
  }
  </code></pre>
  
  <p>=========
  my data provider</p>
  
  <pre><code> public class logProvider&lt;logParsed&gt; extends SortableDataProvider{
  
  /**
   * 
   */
  private static final long serialVersionUID = 1L;
  @SpringBean(name="logParsedDao")
  private logParsedDao logParsedDao;
  
  class SortableDataProviderComparator implements Comparator&lt;logParsed&gt;, Serializable {
  
      public int compare(logParsed log1, logParsed log2) {
          PropertyModel&lt;Comparable&gt; model1 = new PropertyModel&lt;Comparable&gt;(log1, getSort().getProperty());
          PropertyModel&lt;Comparable&gt; model2 = new PropertyModel&lt;Comparable&gt;(log1, getSort().getProperty());
  
          int result = model1.getObject().compareTo(model2.getObject());
  
          if (!getSort().isAscending()) {
              result = -result;
          }
  
          return result;
      }
  
  }
  
  
  private List&lt;logParsed&gt; list =  new ArrayList&lt;logParsed&gt;();
  private SortableDataProviderComparator comparator = new SortableDataProviderComparator();
  
  public logProvider(List&lt;logParsed&gt; sentModel){
  
      setSort("numberOfEntries",SortOrder.DESCENDING);
      list = sentModel;
  }
  
  public Iterator&lt;logParsed&gt; iterator(int first, int count) {
  
      //ArrayList&lt;logParsed&gt; newList = (ArrayList&lt;logParsed&gt;) logParsedDao.findAll();
      //Collections.sort(newList, comparator);
      Iterator&lt;logParsed&gt; iterator = null;
  
      try {
          if(getSort() != null) {
              Collections.sort(list, new Comparator&lt;logParsed&gt;() {
                  private static final long serialVersionUID = 1L;
  
                      public int compare(logParsed sl1, logParsed sl2) {
                       int result=1;
                          PropertyModel&lt;Comparable&gt; model1= new PropertyModel&lt;Comparable&gt;(sl1, getSort().getProperty());
                          PropertyModel&lt;Comparable&gt; model2= new PropertyModel&lt;Comparable&gt;(sl2, getSort().getProperty());
  
                          if(model1.getObject() == null &amp;&amp; model2.getObject() == null) 
                              result = 0;
                          else if(model1.getObject() == null) 
                              result = 1;
                          else if(model2.getObject() == null) 
                              result = -1;
                          else 
                              result = model1.getObject().compareTo(model2.getObject());
  
                          result = getSort().isAscending() ? result : -result;
  
                          return result;
                  }
              });
          }
  
          if (list.size() &gt; (first+count))
              iterator = list.subList(first, first+count).iterator();
          else
              iterator = list.iterator();
      } 
      catch (Exception e) {
          e.printStackTrace();
      }
  
      return iterator;
  
  }
  
  public int size() {
      // TODO Auto-generated method stub
      return list.size();
  }
  
  public IModel&lt;logParsed&gt; model(final Object object) {
      return new AbstractReadOnlyModel&lt;logParsed&gt;() {
          @Override
          public logParsed getObject() {
              return (logParsed) object;
          }
      };
  }
  
   public void setList(List&lt;logParsed&gt; newList){
  
       list = newList;
      }
  </code></pre>
  
  <p>}</p>