-->
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: Fetch not causing eager fetching, instead doing n+1 queries
PostPosted: Wed Jul 09, 2008 1:08 pm 
Newbie

Joined: Thu Jul 03, 2008 10:57 am
Posts: 2
I'm trying to do a simple query, "From Message message Left Join Fetch message.mobileWorker worker" limited to 10 results. My query specifies 'fetch' and hibernate should be doing one query to get the resulting data, however, instead its doing 11 queries. Is there any way to fix this?

- Thanks

Hibernate version: 3.2.5

Mapping documents:

<class name="Message" table="MESSAGES">
<id name="recordId" column="record_id" type="int"/>
<property name="deviceId" column="device_id" type="string" length="16" />
<many-to-one name="mobileWorker" class="Worker" column="mwid" fetch="join" cascade="none" lazy="false" not-null="false" not-found="ignore"/>
</class>

<class name="Worker" table="WORKER" lazy="false">
<id name="mobileWorkerId" column="mobileWorkerId" type="string" length="100"/>
<property name="deviceId" column="device_id" type="string" length="25" insert="false" update="false" />
</class>


Code between sessionFactory.openSession() and session.close():

session.beginTransaction();
Query q = session.createQuery("From Message message Left Join Fetch message.mobileWorker worker ");
q.setMaxResults(10);

List queues = q.list();
System.out.println("count:" + queues.size());


Name and version of the database you are using:
Mysql 5.0.41


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