Hello, I am having a problem to map my objects in a way to fetch them better later.
I used the design pattern Composite to organize projects and subprojects down to activities and i am trying to make dependencies between the activities. When I fetch a dependency, i would like only to fetch an activity, but i am fetching the entire project and sub-projects tree with it. And that is a big search. Here is my mapping file:
Code:
<class name="model.projects.time.Dependency" table="thinktank.dependency" lazy="true">
<id name="dependencyId" column="dependencyid" >
<generator class="increment"/>
</id>
<many-to-one name="antecessor" outer-join="false" class="model.projects.ProjectComponent" lazy="proxy" column="antecessor"/>
<many-to-one name="sucessor" outer-join="false" class="model.projects.ProjectComponent" lazy="proxy" column="sucessor"/>
<property name="hours" column="hours"/>
<property name="kind" column="kind" />
</class>
<class name="model.projects.ProjectComponent" table="thinktank.projectblock">
<id name="blockId" column="blockid" type="long">
<generator class="increment"/>
</id>
<discriminator column="type"/>
<subclass name="model.projects.Activity" lazy="true" discriminator-value="2">
<many-to-one name="father" lazy="proxy" outer-join="false" cascade="none" column="fatherid" class="model.projects.ProjectBlock"/>
<many-to-one name="project" lazy="proxy" outer-join="false" column="projectid" class="model.projects.ProjectBlock"/>
</subclass>
<subclass name="model.projects.Project" lazy="true" discriminator-value="0">
<many-to-one name="father" column="fatherid" cascade="none" class="model.projects.ProjectBlock"/>
<set name="children" lazy="true" inverse="true" cascade="save-update">
<key column="fatherid"/>
<one-to-many class="model.projects.ProjectComponent" />
</set>
</subclass>
<subclass name="model.projects.ProjectBlock" discriminator-value="1">
<many-to-one name="father" lazy="proxy" column="fatherid" class="model.projects.ProjectBlock"/>
<many-to-one name="project" lazy="proxy" column="projectid" class="model.projects.ProjectBlock"/>
<set name="children" inverse="true" lazy="true" cascade="save-update">
<key column="fatherid"/>
<one-to-many class="model.projects.ProjectComponent" />
</set>
</subclass>
</class>
When I search for a project, it brings me all its children, which are projects with more children. It goes down in a tree until it reaches the activities as leaf. I want this tree structure to be greedly fetched on the database.
My problem is that later I get for each activity a dependency. Each dependency has antecessor and sucessors, which are activities. But each activity has a property called project and father, and when i get the project it is greedly searching the tree structure all over again.
Anyone knows how can I map it so the childrens of the project are searched lazily when fetched from a dependency?
Thanks
Miguel