title: Hibernate alias to a simple boolean field
body: <p>I am struggling with the Hibernate Criteria API.</p>
  
  <p>In class <code>Conversation</code> I have:</p>
  
  <pre><code>@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
  @JoinTable(name = "Conversation_ConversationParticipants",
             joinColumns = @JoinColumn(name = "ConversationID"), 
             inverseJoinColumns = @JoinColumn(name = "ConversationParticipantID"))
  private List&lt;ConversationParticipant&gt; participants;
  </code></pre>
  
  <p>And in class <code>ConversationParticipant</code> I have: </p>
  
  <pre><code>@OneToOne
  @JoinColumn(name = "ParticipantID")
  private User participant;
  
  @Type(type = "true_false")
  @Column(name = "Viewed")
  private boolean viewed;
  </code></pre>
  
  <p>In my criteria I have </p>
  
  <pre><code>    Criteria criteria = super.createCriteria();
      criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
      criteria.createAlias("participants", "participants");  
      criteria.createAlias("participants.participant", "participant");
      criteria.add(Restrictions.eq("participant.id", user.getId()));
  
      return (List&lt;Conversation&gt;) criteria.list();
  </code></pre>
  
  <p>This all works ok and I can see all of the conversations for the given user. However, what I want is to see all of the conversations that the user has not viewed yet. To do so, I try to add:</p>
  
  <pre><code>    criteria.add(Restrictions.eq("participants.viewed", false)); 
  </code></pre>
  
  <p>However, this returns 0 conversations (if I put 'true' I get the same result and I have checked db and made sure that there are values with both true and false).  How can I achieve this?  What am I doing wrong? </p>
  
  <p>The query that is run is:</p>
  
  <pre><code>from
      Conversations this_ 
  inner join
      Conversation_ConversationParticipants participan4_ 
          on this_.id=participan4_.ConversationID 
  inner join
      ConversationParticipants participan1_ 
          on participan4_.ConversationParticipantID=participan1_.id 
  inner join
      Users participan2_ 
          on participan1_.ParticipantID=participan2_.id 
  where
      participan1_.Viewed=? 
      and participan2_.id=?
  </code></pre>
  
  <p>DB Table:</p>
  
  <pre><code> CREATE TABLE ConversationParticipants(ID BIGINT NOT NULL IDENTITY, Viewed CHAR(1), Type VARCHAR (255), ParticipantID BIGINT, PRIMARY KEY (ID));
  </code></pre>
  
  <p>Based on the answer below, I was able to make it work by using:</p>
  
  <pre><code> criteria.add(Restrictions.eq("participants.viewed", Boolean.FALSE));
  </code></pre>