title: Hibernate, select by id or unique column
body: <p>I am using hibernate for Java, and I want to be able to select users by id or by name from the database. </p>
  
  <p>Nice thing about Hibernate is that it caches the result by id, but I seem to be unable to make it cache by name.</p>
  
  <pre><code>static Session openSession = Factory.openSession();
  
  public static User GetUser(int Id) {
      return (User) openSession.get(User.class, new Integer(Id));
  }
  
  public static User GetUser( String Name ){
     return (User) openSession.createCriteria( User.class ).
             add( Restrictions.eq("username", Name) ).
             uniqueResult();
  
  }
  </code></pre>
  
  <p>If I use GetUser(1) many times, hibernate will only show that it executed the first time.</p>
  
  <p>But every time I use GetUser("user1"), hibernate shows that it is executing a new query to database.  </p>
  
  <p>What would be the best way to have the string identifier be cached also?</p>