title: spring / hibernate - filter by current user id
body: <p>I have a table CompanyList in my Oracle database :</p>
  
  <pre><code>CMP_ID INTEGER -- ID of company
  CMP_NAME VARCHAR2 -- name of company
  USR_ID INTEGER -- Foreign key to the USERS table
  </code></pre>
  
  <p>i have my Spring 3 MVC app all configured using annotations, my POJOs as well , my DAO objects (CompanyDao) using hibernate to retrieve for exemple a list of companies.</p>
  
  <p>CompanyDao :</p>
  
  <pre><code>@Transactional
      public Set&lt;Company&gt; findAllCompanys() throws DataAccessException {
  
          return findAllCompanies(-1, -1);
      }
  
      @SuppressWarnings("unchecked")
      @Transactional
      public Set&lt;Company&gt; findAllCompanies(int startResult, int maxRows) throws DataAccessException {
          Query query = createNamedQuery("findAllCompanies", startResult, maxRows);
          return new LinkedHashSet&lt;Company&gt;(query.getResultList());
      }
  </code></pre>
  
  <p>And my company domain :</p>
  
  <pre><code>@Entity
  @NamedQueries( {
          @NamedQuery(name = "findAllCompanies", query = "select myCompany from Company myCompany")})
  ...
  public class Company implements Serializable {
  ...
  </code></pre>
  
  <p>Then I setup spring security, so all my pages require identification.</p>
  
  <p>What is the best way to filter the rows returned by CompanyDao, using the USER ID of the current logged in user session ?</p>