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;
}
}