title: Hibernate retrieve results from database based on condition
body: <p>I am a bit lost when it comes to retrieving results from the database.</p>
  
  <p>My <code>MemberModel</code> consists of 4 fields: <code>id</code>, <code>username</code>, <code>password</code> and <code>email</code>. I have been able to successfully save it to database.</p>
  
  <p>Now I need to retrieve an <code>id</code> of a member who's <code>username</code> equals "Test".</p>
  
  <p>I tried something along the lines:</p>
  
  <pre><code>SQLQuery query = session.createSQLQuery("SELECT id FROM members WHERE username = :username");
  query.setString("username", username);
  List&lt;MemberModel&gt; returnedMembers = query.list();
  MemberModel member = returnedMembers.get(0);
  int id = member.getId();
  </code></pre>
  
  <p>However I get an error that <code>member.getId()</code> cannot be converted to int, since it is <code>MemberModel</code>... But the getter <code>getId()</code> returns <code>int</code>.</p>
  
  <p>I am quite confused. The question is: what would be the easiest and fastes way to retrieve member <code>id</code> based on condition (value of <code>username</code>)?</p>