I have a super class Disc and two child classes : AudioDisc and VideoDisc. I am trying both the strategy Union subclass and join Subclass but i could not find any way to lazy load the subClass.
My classes are something like this :
Code:
public class Reservation {
private int id ;
private Set<Disc>discs = new HashSet<Disc>();
public Set<Disc> getDiscs() {
return discs;
}
public void setDiscs(Set<Disc> discs) {
this.discs = discs;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
Code:
public class Disc {
private int id ;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
Code:
public class AudioDisc extends Disc{
private String singer ;
private int numOfSongs ;
public String getSinger() {
return singer;
}
public void setSinger(String singer) {
this.singer = singer;
}
public int getNumOfSongs() {
return numOfSongs;
}
public void setNumOfSongs(int numOfSongs) {
this.numOfSongs = numOfSongs;
}
}
Code:
public class VideoDisc extends Disc{
private String director ;
private String language ;
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
}
Now when i am calling
List<Reservation>reservations = query.list();
in main()
and calling getDiscs() overs each reservation object the sql is fired to join or union (based on the strategy defined in mapping) to fetch the data from DB. can we set the lazy loading of these subclass ?? i mean to say that the sql corresponding to that subclass should not be fired untill we have not accessed the property of the class . If it is not possible then what is the use of providing the lazy attribute in the metadata definition of joinsubclass or unionsubclass (which holds the default value "false").
Any help is appreciated .
Thanks.