-->
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: Caching in Hibernate
PostPosted: Mon Jul 18, 2005 7:44 pm 
Regular
Regular

Joined: Tue Nov 09, 2004 5:15 pm
Posts: 100
Hi All,

Currently we've a non-hibernate based architecture where we've implemented caching the result set at session level.

In the architecture that we just started to work, we'll be using Hibernate. I've following questions regarding this. I would greatly appreciate any input on this.

1. We'll be running our application in Clustered environment and hence we'll use JBoss Cache. Per my understanding (as it's my first hibernate application, i may be wrong), second level cache is synchronized across the cluster meaning, if user A runs a query (list of products) through server A, the second level cache caches the result set. Now user A adds new product. After that user B queries list of products. As the second level cache is configured and clustered, will user B's query to ge tthe list of product include the new product that user A added?


2. Let say i'm running the query to get the list of products. There are 1500 products. Each product has related objects Equipment, ProblemCause, MonitoringDetails etc. Client needs only 50 rows to start with. Is it possible to return first 50 rows immediately after it becomes available and then move on with reading the rest of the objects???


3. Let us say Product has references to object A, B, C and D. But client is interested in only Product and related object As. (don't want B,C and D). Is it possible to read all As but not B, C and D?

4. Our client is non-java (Mac OS X). Hence we need to convert the query results into some XML format and send it. Let us say user A queries the list of Products which has references to object A. So we need to run the query as follows: (let us assume that lazy is "true")

List data = ...find("from product where product.id=?"....)
for(Iterator itr=data.iterator(); itr.hasNext(); ) {
Product product = (Proudct)itr.next();
product.getA();
}

Is that recommended?


Thanks for any input on these questions!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 7:51 pm 
Senior
Senior

Joined: Thu May 12, 2005 11:40 pm
Posts: 125
Location: Canada
1. Clustered caching is usually accomplished using clustered invalidation, rather than processes updating each others caches. Be sure you actually need it though, clustered cache management can be slower than just going to the database unless you run very complex queries.

2. You can do this using Query's pagination functions.

3. Yes, fetch="join", fetch="select", etc.

4. Query has an iterate() method which is useful when you expect most of the objects will be found in cache.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 8:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
(1)

(a) The post by Nebob is incorrect. This stuff depends upon the cache provider. You are using JBossCache which is a replicated cache. Some other clustered caches do invalidation only, but not JBossCache.

(b) You do not understand Hibernate's cache architecture. You need to learn about the difference between the query cache and the second level cache. Try HiA.


(2) What does "after it becomes available" mean? I think you are asking about query pagination. See setMaxResults()/setFirstResult(). Again, read the documentation or HiA.

(3) Of course. RTFM.

(4) Huh??


Please spend some time reading the docs or book. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 8:15 pm 
Regular
Regular

Joined: Tue Nov 09, 2004 5:15 pm
Posts: 100
Thanks Gavin and NeBob.


1a. Gavin, does your answer mean that the user B will see the changes made by user A through second level cache? (I assume "yes")

1b. I understand the difference between session level cache and second level cache but not clear with query cache yet. Will do more reading on it.

2. Thanks.

3. What i mean by "when it becomes available", i don't want to wait for hibernate to read/construct 1500 objects (and the related objects) before i return the first 50 objects to my client.


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.