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.  [ 4 posts ] 
Author Message
 Post subject: Forcing non-laziness
PostPosted: Fri Feb 27, 2009 7:29 am 
Newbie

Joined: Fri Feb 27, 2009 7:01 am
Posts: 5
Hibernate version: 3.3.1

Hy all

I'd like to know if there is a way of forcing non-laziness from the code (other than explicitly calling all the getters).

I'd like most of my association to be lazily loaded when running in the server but forcing a full load before sending a graph of object to the client where my session will have disappeared and so will generate an error.

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2009 9:11 am 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
I have never tried this myself but this might be what your looking for

http://www.hibernate.org/315.html
Quote:
Programmatically override or completely redefine fetching at runtime through API and queries:

* Criteria respects the laziness settings in your mappings and guarantees that what you want loaded is loaded. This means one Criteria query might result in several SQL immediate SELECT statements to fetch the subgraph with all non-lazy mapped associations and collections. If you want to change the "how" and even the "what", use setFetchMode() to enable or disable outer join fetching for a particular collection or association. Criteria queries also completely respect the fetching strategy (join vs select vs subselect).

* HQL respects the laziness settings in your mappings and guarantees that what you want loaded is loaded. This means one HQL query might result in several SQL immediate SELECT statements to fetch the subgraph with all non-lazy mapped associations and collections. If you want to change the "how" and even the "what", use LEFT JOIN FETCH to enable outer-join fetching for a particular collection or nullable many-to-one or one-to-one association, or JOIN FETCH to enable inner join fetching for a non-nullable many-to-one or one-to-one association. HQL queries do not respect any fetch="join" defined in the mapping document.

* At the moment no batch or subselect fetching override is available dynamically. Both Criteria and HQL respect the settings defined in the mapping document if additional SELECT statements must be executed to load the non-lazy mapped associations and collections.


_________________
Please rate my replies as I need points for all of my questions also.


Top
 Profile  
 
 Post subject: Re: Forcing non-laziness
PostPosted: Fri Feb 27, 2009 9:35 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 8:25 am
Posts: 46
Location: Saint Petersburg, Russian Federation
willix wrote:
Hibernate version: 3.3.1

Hy all

I'd like to know if there is a way of forcing non-laziness from the code (other than explicitly calling all the getters).

I'd like most of my association to be lazily loaded when running in the server but forcing a full load before sending a graph of object to the client where my session will have disappeared and so will generate an error.

thanks


Hibernate.initialize()


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2009 9:57 am 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
Denis:
Quote:
Note: This only ensures intialization of a proxy object or collection; it is not guaranteed that the elements INSIDE the collection will be initialized/materialized.


I would agree with you except he doesn't want to call the getters and setters and if he is going deeper into the object (beyond the first level) he will have to do that.

It's a good suggestion though.

_________________
Please rate my replies as I need points for all of my questions also.


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