-->
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: Hibernate fires two queries while dealing with parent child
PostPosted: Tue Jun 26, 2012 1:38 pm 
Newbie

Joined: Sat Dec 31, 2011 3:08 am
Posts: 1
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.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.