-->
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.  [ 5 posts ] 
Author Message
 Post subject: Sub sub dependencies
PostPosted: Fri Jan 27, 2006 11:24 am 
Beginner
Beginner

Joined: Mon Jan 31, 2005 11:04 am
Posts: 21
Hi,

I have a graph like that:

user -> blocks -> blockDetails

A user has a colelction of blocks and each block has a collection of blockDetail

Code:
class User {
public Collection blocks;
}

class Block {
public Collection blockDetails;
}

class BlockDetail {
}


I would like to change the fetchMode to JOIN of each relation at runtime using the Criteria API:

Code:
criteria.setFetchMode("blocks", FetchMode.JOIN).addCriteria("blocks", "block").setFetchMode("blockDetails",  FetchMode.JOIN);


It doesn't seem to work with more than one relation level.

It is possible to go till the deepest collection using Criteria??

thanks

Bruno


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 12:58 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
I think that there was a coment about this in the reference.

With HQL you could do
Code:
from User u left join fetch u.blocks b left join fetch b.details


Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 7:25 am 
Beginner
Beginner

Joined: Mon Jan 31, 2005 11:04 am
Posts: 21
I know it possible to do it in HQL but I would like to use the Criteria API. Any idea about how to do it?

schuer


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 1:48 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Have a look in the api for setFetchMode or read the javaDoc. When I move my mouse cursor over session.setFetchMode I see the following:

Code:
Criteria org.hibernate.Criteria.setFetchMode(String associationPath, FetchMode mode)
Specify an association fetching strategy for a one-to-many, many-to-one or one-to-one association, or for a collection of values.

Parameters:
[b]associationPath a dot seperated property path[/b]
mode the fetch mode
Returns:
the Criteria object for method chaining

Of course you must have the hibernate source attached defined.
The following will work:
Code:

session.createCriteria(Department.class).setFetchMode(
            "teams", FetchMode.JOIN).setFetchMode("teams.members",
            FetchMode.JOIN).list();


Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 29, 2006 8:25 am 
Beginner
Beginner

Joined: Mon Jan 31, 2005 11:04 am
Posts: 21
Sebastian,

Indeed it working like that. Thanks a lot for your help ;-)

Bruno


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.