-->
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.  [ 1 post ] 
Author Message
 Post subject: Optimize loading of object
PostPosted: Wed Dec 24, 2008 6:39 am 
Newbie

Joined: Mon Nov 03, 2008 12:27 pm
Posts: 5
Hi,
I would like to optimize the load from database of three types of object in my application:
-Bloc
-Zone
-SubZone
Relations between these objects are:
- a "Bloc" can contain n Zone (OneToMany)
- a "Zone can contain n SubZone (OneToMany)

I would like to load all objects of this types from my database, how can I optimize this loading with hibernate?
I try to do three hql queries (one for all Bloc, one for all Zone and one for all SubZone), but when I navigate in object graph, some database access are done.
=>For each Bloc, when I call getZones() method
=>For each Zone, when I call getSousZones() method
Thanks for help

Code:
@Entity
@Table(name="BIB_U_BLOC"
)
public class Bibubloc implements java.io.Serializable
{

    private String id;
     private String libelle;
     private Set<Bibuzone> bibuzones = new HashSet<Bibuzone>(0);

    public Bibubloc() {
    }
   
   ...
   
   @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="ID_BLOC")
    public Bibubloc getBibubloc() {
        return this.bibubloc;
    }
   
   @OneToMany(fetch=FetchType.LAZY, mappedBy="bibubloc")
    public Set<Bibuzone> getBibuzones() {
        return this.bibuzones;
    }
}

@Entity
@Table(name="BIB_U_ZONE"
)
public class Bibuzone implements java.io.Serializable
{


     private String id;
     private Bibubloc bibubloc;
     private String libelle;
     private String description;
     private Set<Bibusouszone> bibusouszones = new HashSet<Bibusouszone>(0);

    public Bibuzone() {
    }
   
   ...
   
   
   
   @OneToMany(fetch=FetchType.LAZY, mappedBy="bibuzone")
    public Set<Bibusouszone> getBibusouszones() {
        return this.bibusouszones;
    }
   
}


@Entity
@Table(name="BIB_U_SOUSZONE"
)
public class Bibusouszone implements java.io.Serializable
{

     private String id;
     private Bibcchampsaisie bibcchampsaisie;
     private Bibuzone bibuzone;
     private String sousZone;
     private String libelle;
     private String description;

    public Bibusouszone() {
    }

   ...
   
   @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="ID_ZONE", nullable=false)
    public Bibuzone getBibuzone() {
        return this.bibuzone;
    }
}


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

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.