Hi,
I have two entities like Student and ClassMonitor.
Student entity is mapped with student table. The student table contains list of students.
ClassMonitor entity is mapped to class_monitor table.This table contains the id of a student who is monitor.
Now all students will not be monitor, so there will be references of those studentids only in class_monitor table who are monitor.
There is OneToOne mapping between Student entity and ClassMonitor entity.
Now when I query for the students who are not monitor i.e. for which there is no references in the student table then hibernate fires two queries one to get data from student table and other to get data from class_monitor table. But the first query which it fires is a left outer join between student table and class_monitor table which pulls information from both the tables. But it again fires a second query to get info from class_monitor table.
But if a student is a monitor then it does not fires a second query because in this case it get the data from both the tables using left outer join from the first query itself.
Can somebody provide any suggestions to always fire only one query in both the cases?
Thanks.
|