-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Searching lazily from a tree structure.
PostPosted: Tue Jan 08, 2008 2:24 pm 
Newbie

Joined: Tue Jan 08, 2008 2:13 pm
Posts: 1
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


Top
 Profile  
 
 Post subject: Re: Searching lazily from a tree structure.
PostPosted: Wed Jan 09, 2008 6:02 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Try forcing fetching to SELECT on the associations and also cache the objects and associations even for a short period or whatever period you believe is long enough for the code between the point it loads the graph and a project from a activity is accessed. This will eliminate extra trips to database and improve performance significantly.



Farzad-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.