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
|