title: In memory filtering of not persistent collection with Hibernate
body: <p>Ok. What I wanted was: 
    With Hibernate, to load once a list of MyEntity objects and have that list as the internal data of a model of a jtable. I also have a jTextField and when a key is typed, i call a method of my model that takes the text of the jtextfield as argument and filters the internal list of MyEntitys and fires the tablemodel change event. I want to do that filtering without hitting the database everytime.</p>
  
  <p>What I did was:
  I kept 2 lists inside the model: The one named initialList, that was only once loaded with createCriteria(...).list(), and a second list named filteredList, that whenever the refresh method was called it was populated like this:</p>
  
  <pre><code>public void refresh(String filterText)
  {
     filteredList = session.createFilter(initialList, "where property= ?")
       .setParameter( 0, filterText)
      .list();
  }
  </code></pre>
  
  <p>Then I used this filtered list to give the jtable the row,column value.
  Well, It didnt work because Hibernate says that the filter API stuff can be used only in persistent collections. So I have the following 3 questions:</p>
  
  <ol>
  <li>Essentialy If i create a dummy parent entity(along with the dummy parent table in the database) that will contain all of the MyEntity rows as child collection and load this parent dummy entity, this will work? If yes, it sounds silly to do this, just to make hibernate consider the collection persistent and let me use the filter stuff. What am I missing?</li>
  <li>Suppose I do have a persistent collection and use the filter API, does this guarantee that I will never hit the database except from the initial loading? I dont care being updated, just load once and then filter QUICKLY, because I need to filter every time the user presses a key.</li>
  <li>Is there any other way to get this functionality. I suppose I could manually use the Java Collections API to sort filter index and stuff, but any other ready made way?</li>
  </ol>
  
  <p>Thanks in advance. </p>