title: Hibernate- @OnetoMany with Where clause on Collection
body: <p>In my One-to-Many and Many-to-One bi-directional relation, I want execute the following sql-</p>
  
  <pre><code>select * from user_credential c 
  join user_profile p on c.login_id = p.login_id
  join user_address a on p.address_id = a.address_id
  where p.profile_id = 1
  </code></pre>
  
  <p>But, I'm getting the result of the sql-</p>
  
  <pre><code>select * from user_credential c 
  join user_profile p on c.login_id = p.login_id
  join user_address a on p.address_id = a.address_id
  where p.credential_id = 1
  </code></pre>
  
  <p>The hibernate entity details-</p>
  
  <pre><code>    @Entity
      @Table(name = "user_credential")
      public class UserCredential implements Serializable {
          private static final long serialVersionUID = -2839071606927921689L;
  
          @Id
          @GeneratedValue(strategy = GenerationType.AUTO)
          @Column(name = "login_id", insertable = false, updatable = false, nullable = false)
          private int login_id = 0;
  
          @Column(name = "password", insertable = true, updatable = true, nullable = false)
          private String password = null;
  
          @OneToMany(mappedBy = "login_id", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
          private Set&lt;UserProfile&gt; profiles = null;
  //getters/setters
  }
  
  @Entity
  @Table(name = "user_profile")
  public class UserProfile implements Serializable {
  
      private static final long serialVersionUID = 5765280899633539336L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "profile_id", length = 10, insertable = false, updatable = false, nullable = false)
      private int profile_id = 0;
  
      @ManyToOne
      @JoinColumn(name = "login_id", insertable = true, updatable = true, nullable = false)
      private UserCredential login_id = null;
  
      @Column(name = "name", length = 20, insertable = true, updatable = true, nullable = false)
      private String name = null;
  
      @Column(name = "age", length = 3, insertable = true, updatable = true, nullable = false)
      private byte age = 0;
  
      @OneToMany(mappedBy = "profile_id", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
      private Set&lt;UserAddress&gt; address = null;
  
  //getters/setters
  }
  
  @Entity
  @Table(name = "user_address")
  public class UserAddress extends BaseTable{
      private static final long serialVersionUID = 5036341911955664992L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "address_id", length = 10, insertable = false, updatable = false, nullable = false)
      private int address_id = 0;
  
      @ManyToOne
      @JoinColumn(name = "profile_id", insertable = true, updatable = true, nullable = false)
      private UserProfile profile_id = null;
  
      @Column(name = "state", length = 20, insertable = true, updatable = true, nullable = false)
      private String state = null;
  
      @Column(name = "city", length = 20, insertable = true, updatable = true, nullable = false)
      private String city = null;
  //getters/setters
  }
  </code></pre>
  
  <p>HQL:</p>
  
  <pre><code>select credential from UserCredential credential
  join credential.profiles profile
  where  profile.profile_id = 1
  </code></pre>
  
  <p>I'm not understanding, why hibernate is filtering the data on parent id and also, how my required sql will be executed. I'm using hibernate 4.3.8</p>
  
  <p>Please tell, if any other information is necessary.</p>