Unable to retrieve associated children’s through HQL query using inner
join fetch

Here are the mapping for parent, child and school

//Parent
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"  default-
lazy="false">

  <class name="Parent">
    <id name="ID" type="System.Guid">
      <generator class="guid.comb"/>
    </id>
    <bag name="Childrens" table="Child" cascade="delete-orphan"
lazy="true">
      <key column=" ParentID" />
      <one-to-many class="Child" />
    </bag>
  </class>
</hibernate-mapping>

//Child
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
lazy="false">
  <class name="Child">
    <id name="ID" type="System.Guid">
      <generator class="guid.comb"/>
    </id>

    <property name="Name"/>
<many-to-one name="School" class="School" column="SchoolID"
cascade="none" not-null="true" fetch="join"/>
  </class>
</hibernate-mapping>

// School
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
lazy="false">
  <class name="School">
    <id name="ID" type="System.Guid">
      <generator class="guid.comb" />
    </id>
    <property name="SchoolDistrict" not-null="true"/>
  </class>
</hibernate-mapping>


    FROM Parent as parent
    inner join fetch parent.Childrens as child
    inner join fetch child.School
    WHERE parent.ID = :parentID
    AND child.Name is not null

After executing above HQL query we see correct number of parent
objects returned but associated objects parent.Childrens has wrong
number of children’s as if filter (child.Name is not null) was not
applied.


We would like to return all the children whose name is not null with
below HQL query

    SELECT child FROM Parent as parent
    inner join fetch parent.Childrens as child
    inner join fetch child.School
    WHERE parent.ID = :parentID
    AND child.Name is not null

Doesn’t seem to work either.

Any ideas?


Thanks

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to