-->
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: Optimisation chargement objet
PostPosted: Tue Dec 23, 2008 10:57 am 
Newbie

Joined: Mon Nov 03, 2008 12:27 pm
Posts: 5
Bonjou,
Je souhaite optimiser le chargement de trois types d'objet dans mon application:
-Bloc
-Zone
-SousZone
En terme de relation:
-j'ai un bloc qui peut contenir n Zone (OneToMany)
-j'ai une zone qui peut contenir n SousZone (OneToMany)

Sachant que je veux charger tous les objets de ces trois types dans mon application, comment puis je optimiser ce chargement avec hibernate.
J'ai essayé de faire 3 requetes (1 pour chaque type d'objet), mais lorsque je parcours mon graphe d'objets j'ai néanmoins des accès en base:
pour chaque bloc, lorsque j'accède à la méthode getZones()
pour chaque zone, lorsque j'accède à la méthode getSousZones()

Merci pour votre aide.

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  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 9:25 am 
Beginner
Beginner

Joined: Thu Jun 30, 2005 1:04 pm
Posts: 26
Bonjour,

En première approche, j'utiliserai un subselect entre bloc et zone et un fetch à eager entre zone et sous zone, ou l'inverse en fonction des cardinalités.

Voir [url]file:///D:/jraf/hibernate/hibernate-annotations-3.3.0.GA/doc/reference/fr/html_single/index.html#d0e2245[/url] pour subselect @Fetch avec SUBSELECT
Voir [url]file:///D:/jraf/hibernate/hibernate-annotations-3.3.0.GA/doc/reference/fr/html_single/index.html#d0e1585[/url] pour eager

Bon courage


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.