-->
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: Redundant queries generated with Criteria API
PostPosted: Tue Feb 27, 2007 7:32 pm 
Newbie

Joined: Tue Jul 04, 2006 5:23 pm
Posts: 2
Hi,

We have a performance issue we're trying to resolve.
(All names changed to protect the innocent).

Our data model is quite simple:
Class A maps to table A
Class B maps to table B

Table B has a foreign key pointing to table A.

Class A has a list of B's.

In simplified code form:
Code:
class A {
  List bs; // plus setters and getters for this and other properties.
}


Mapping fragment from A:
Code:
<list name="bs" lazy="false" fetch="join">
   <key column="A_ID" not-null="true" update="false"/>
   <list-index column="A_ORDER"/>
   <one-to-many class="B" />
</list>


Mapping fragment from B:
Code:
<many-to-one name="a" column="A_ID" not-null="true" insert="false" update="false"/>


Now for the problem we face:
The following HQL query generates one SQL query as expected and desired:
Code:
from A a join fetch a.bs


However when I do the following Criteria query, I get n+1 SQL queries.
Code:
session.createCriteria(A.class).setFetchMode("bs", FetchMode.JOIN).createCriteria("bs").list();


However if I remove the
Code:
createCriteria("bs")
then it goes back to a single query.

This is the simplest I can describe our issue.

The obvious workaround is to rewrite our code to use HQL, but the code we have is quite a large involved user driven search, and hence why we're using the Criteria interface.

Is this a problem with the Criteria queries or is there something I am doing incorrectly?


I am using hibernate v3.1.3.


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.