title: Hibernate Criteria query using AND,OR operator
body: <p>In my application I have two entity class <code>User</code>,<code>Activity</code>.</p>
  
  <p>Activity class is :</p>
  
  <pre><code> public class Activity{
   private Set&lt;User&gt; users;
   private Set&lt;User&gt; activityManagers;
   }
  </code></pre>
  
  <p>and class User is :</p>
  
  <pre><code> public class User{
   private String userName;
   }
  </code></pre>
  
  <p>Now I want to retrieve, using Hibernate Criteria all <code>Activities</code> having a <code>User</code> with <code>username</code> set to a certain value, in property <code>users</code> or <code>managers</code> or both.
   I have tried this:</p>
  
  <pre><code>Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(Activity.class, "act");
  criteria.createAlias("act.activityManagers", "manager");
  criteria.createAlias("act.users", "user");
  criteria.add(Restrictions.disjunction().add(Restrictions.eq("manager.username", userName)).add(Restrictions.eq("user.username", userName)));
  criteria.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);
  </code></pre>
  
  <p>It is not working properly .Where I have done wrong I don't know. can anyone help me? Thanks </p>
  
  <p>UPDATE-1
    Suppose I have 5 <code>Activity</code>s</p>
  
  <pre><code>First Activity:users[aaa,bbb,cccc],managers[ddddd].
  Second Activity:users[userName,dddd],managers[userName,xxx,gggg].   
  Third Activity:users[userName,vvvvv,bbbb],managers[sss,cccc,tttt].
  Fourth Activity:users[aaa,ffff,jjjj],managers[userName,uuuu,iiiii].
  Fifth Activity:users[dddd,ffff],managers[jjjjj,iiii].
  </code></pre>
  
  <p>Result must be Second,Third,Fourth Activity. But I am getting only Thired Activity.</p>