-->
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: change fetching strategy to lazy!?
PostPosted: Wed Feb 15, 2006 3:19 pm 
Newbie

Joined: Wed Feb 15, 2006 3:13 pm
Posts: 5
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hi!! I would like to change the fetching strategy to lazy at runtime. Is it possible? I've seen examples of changing from lazy to imediate, for example. But I would like to use no lazy (lazy=false) and at runtime, for some other situation, change fetching strategy to lazy.
It would be something like:

select * from user fetch lazy...
don't know..
Thanks in advance..


Top
 Profile  
 
 Post subject: Re: change fetching strategy to lazy!?
PostPosted: Wed Feb 15, 2006 3:30 pm 
Newbie

Joined: Wed Feb 15, 2006 9:22 am
Posts: 7
Location: Florham Park, NJ
iconst;

Using a criteria query, you could override the fetch mode. Hibernate 3 has deprecated the LAZY option, but the replacement is SELECT, in contrast with JOIN (which replaces EAGER).

For example, in a Order/OrderItems parent/child scenario:

Code:
session.createCriteria(Order.class).createCriteria("orderItems").setFetchMode(FetchMode.SELECT);


If your mapping defined the relationship between Order and OrderItems as lazy="false", you would override it with the criteria above.

//Nicholas


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 15, 2006 8:44 pm 
Newbie

Joined: Wed Feb 15, 2006 3:13 pm
Posts: 5
thanks in advance! but can it be done in HQL?? I am in a situation where I cant use Criteria (join with other objects...)


Top
 Profile  
 
 Post subject: Re: change fetching strategy to lazy!?
PostPosted: Thu Feb 16, 2006 8:31 am 
Newbie

Joined: Wed Feb 15, 2006 9:22 am
Posts: 7
Location: Florham Park, NJ
I see what you mean. I do not think it can be done in raw HSQL. But you can join to other objects in criteria queries. My example above joins order items and orders, but you can also make arbitrary associations.

//Nicholas


Top
 Profile  
 
 Post subject: thanks!!
PostPosted: Thu Feb 16, 2006 9:22 am 
Newbie

Joined: Wed Feb 15, 2006 3:13 pm
Posts: 5
but, it really needs to be done in hql... could someone help me!?


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.