-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with setFetchMode() on Subcriteria of Subcriteria
PostPosted: Thu Jan 26, 2006 10:44 am 
Newbie

Joined: Mon Sep 13, 2004 9:44 am
Posts: 13
Hibernate version: 3.1.0

I think there may be a bug in CriteriaImpl$Subcriteria.setFetchMode() when the Subcriteria was created from another Subcriteria.

I'm querying a structure that looks like this:

entity->many-to-one(assoc1)->entity->many-to-one(assoc2)->entity->collection

The following code works (it performs the fetch join on the collection)...

Code:
session.createCriteria (entityClass).
    createCriteria ("assoc1").
        setFetchMode ("assoc2.collection", FetchMode.JOIN)


...but this doesn't work (the fetch join is not performed)...

Code:
session.createCriteria (entityClass).
    createCriteria ("assoc1").
        createCriteria ("assoc2").
            setFetchMode ("collection", FetchMode.JOIN)


Using the debugger, I noticed that CriteriaImpl$Subcriteria.setFetchMode() calls CriteriaImpl.setFetchMode() with a qualified path. However, in the failing case, the qualified path is "assoc2.collection", not "assoc1.assoc2.collection".

I've simplified the example queries. In reality they contain restrictions at the outer-most and inner-most nesting levels.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 11:29 am 
Beginner
Beginner

Joined: Mon Jan 31, 2005 11:04 am
Posts: 21
I have the same problem, I solved it using HQL:

StringBuffer strQuery = new StringBuffer(1000);
strQuery.append("from Project p ")
.append("left join fetch p.savedQuantification q ")
.append("left join fetch q.blocks bl ")
.append("left join fetch bl.blockDetails bd ")
.append("left join fetch bd.savings s ")
.append("left join fetch p.spendArea ")
.append("left join fetch p.cluster ")
.append("left join fetch p.spendCategory ")
.append("left join fetch p.region ")
.append("left join fetch p.businessGroup ")
.append("left join fetch p.hub ")
.append("left join fetch p.site ")
.append("left join fetch p.owner ")
.append("left join fetch p.milestoneStatus ")
.append("left join fetch p.backupOwner ")
.append("left join fetch p.projectStatus ")
.append("left join fetch p.multipleSite ")
.append("left join fetch p.milestones ")
.append("left join fetch p.implementationBarriers ")
.append("where p.id = " + id);

return (Project) uniqueElement(getHibernateTemplate().find(strQuery.toString()));



But I would prefere using the Criteria class instead of HQL.

Help would be welcome.

schuer


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 12:02 pm 
Newbie

Joined: Mon Sep 13, 2004 9:44 am
Posts: 13
schuer wrote:
I have the same problem, I solved it using HQL:

...snip...

But I would prefere using the Criteria class instead of HQL.

Help would be welcome.

schuer


I've shown working code using the criteria API, it's just not as pretty as the broken version! You can also use Criteria.createAlias() to refer to associated entities.

Chris.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

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.