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.  [ 2 posts ] 
Author Message
 Post subject: Two questions about Lazy and update
PostPosted: Tue Dec 02, 2008 4:24 pm 
Newbie

Joined: Mon Jul 09, 2007 9:32 am
Posts: 17
Two questions

No. 1

I have one-to-many List set as Lazy. In search, I found if I use findById and detached creita will load List automatically, if I use find (HQL), it will not load the List.

Anybody knows why ? If I want a strict "Lazy", in any scenario, don't load the List, what should I do ?

No.2
If an object has a List which contains 10 elements, some of them are NOT changed, then we don't need to do UPDATE for performance. but I realize that Hibernate will not do this way, how could we improve it ?

Thanks.


Top
 Profile  
 
 Post subject: Re: Two questions about Lazy and update
PostPosted: Thu Dec 04, 2008 1:59 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
czy11421 wrote:
Two questions

No. 1

I have one-to-many List set as Lazy. In search, I found if I use findById and detached creita will load List automatically, if I use find (HQL), it will not load the List.

Anybody knows why ? If I want a strict "Lazy", in any scenario, don't load the List, what should I do ?

No.2
If an object has a List which contains 10 elements, some of them are NOT changed, then we don't need to do UPDATE for performance. but I realize that Hibernate will not do this way, how could we improve it ?

Thanks.



For No.1, I am not sure about the Criteria API since I rarely use it but in HQL, to the best of my understanding, if your query starts with from then the configuration is taken into account. however, if your statement start with a select then the query specifies what needs to be fetched.


For No.2, this is the default behaviour but you need to have the colleciton in memory so that hibernate can detect which ones are modified. In many case the collection is coming from outside and it is not in the L1 cache. If you like to get around this, you need to enable a second level cache to avoid performance disasters, and then you need to fetch the collection before replacing it with the new one. Hibernate will take care of the rest. One another point, for class you can instruct hibernate to do a select before update. This might be also possible for collection. And ah, don't forget that caching a collection is good enough. You need to enable caching on the entities that might be inside your collection otherwise hibernate will do a good couple of selects to get those.


Farzad-


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