-->
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: Second level cache question
PostPosted: Mon Oct 12, 2009 10:35 pm 
Newbie

Joined: Wed Aug 26, 2009 3:29 am
Posts: 5
Hello, i am working with hibernate second level cache. I have already configure and activate it.. But im not statisfied that it is fully working.Based on my research and what i've read on the sample in net. After the object is loaded to cache, it will cut 50-70 percent on its loading time..In my program i'm getting almost the same loading time (in miliseconds) every time i called a process which load the same object. How can i assure that my second-level cache is fully working.. Can anyone help me?

Here is the log in my tomcat:

[http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1830819
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1839827
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1842521
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1848512
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1852080
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1866928
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1873554
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1874178
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1877083
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1878320
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1883315
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1887246
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1889448
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1899559
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1903456
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1911216
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1917414
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1919508
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1933371
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1933393
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1938679
> [http-80-1] ReadOnlyCache.put(58) | Caching:
> com.company.project.model.GroupProduct#1943884


Top
 Profile  
 
 Post subject: Re: Second level cache question
PostPosted: Tue Oct 13, 2009 3:47 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
to know if it's working you should try reloading the same object twice: verify the first time you hit the database and the second time you hit the cache. From your log it appears you're working on a different entity each time.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Second level cache question
PostPosted: Tue Oct 13, 2009 4:24 am 
Newbie

Joined: Wed Aug 26, 2009 3:29 am
Posts: 5
Thanks grinovero for the suggestion. You are right based on the my logs in loads different entity of GroupProduct. I assume that those in entity is now my cache after first attempt. To make it clearer, i have called a function that loads list of GroupProduct entity. In my second attempt in loading same list. I have same result of loading time compared to my first load. That is what i've been wondering all this time.

Here is what im doing in DAOHibernate in determining the loading time:


Code:
    public List<GroupProduct> findByServiceId(String serviceId) {
       Long serviceIdLong = Long.valueOf(serviceId);
       List<GroupProduct> gpDTOList = new ArrayList<GroupProduct>();

       long a = System.currentTimeMillis();
   log.debug("start time -  DAO: " + a);

GroupProduct as gp where version=0 and serviceID=?", serviceIdLong);
       
      gpDTOList = getHibernateTemplate().find("from GroupProduct gp where gp.version=0 and gp.serviceID=" +  serviceIdLong);
      
       
       long b = System.currentTimeMillis();
   log.debug("Execution time - DAO: " + (b - a) + " ms");
      
       return gpDTOList;
    }


Here is the log:

First load: 3983 ms
Second load: 3582 ms
Third load : 3402 ms

I'm having same loading time. Even same entity is called. Weird. Please help..


Top
 Profile  
 
 Post subject: Re: Second level cache question
PostPosted: Thu Oct 15, 2009 9:39 pm 
Newbie

Joined: Wed Aug 26, 2009 3:29 am
Posts: 5
DEBUG [main] CacheFactory.createCache(39) | instantiating cache region: com.company.project.model.
GroupProduct usage strategy: read-only
WARN [main] CacheFactory.createCache(43) | read-only cache configured for mutable class: com.company
.project.model.GroupProduct

Do i need to add @mutable annotation to be object? above is the logs in my tomcat.. I still Didn't find any solution or
clear explanation about what might be the cause, why it is still loading same duration as first load. Although the logs shows my entity is being cache it has no effect in loading speed after first load. Any help?

GroupProduct class:
Code:
@Entity @Table(name="group_product")
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class GroupProduct extends BaseObject {
    private Long id;
    ....
    ....


Top
 Profile  
 
 Post subject: Re: Second level cache question
PostPosted: Fri Oct 16, 2009 7:59 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
Do i need to add @mutable annotation to be object?

No, it's the other way around: your entities are mutable, it's the cache which needs to be declared read-write but is read-only.

About your previous question, Hibernate is very careful in not enabling caches if you're not really sure and aware of the subtle consequences. So enabling caching for a single-object load requires:
* to enable the second level cache globally (and configure it)
* to enable caching on the entity

Both need to be true, or it won't use it.

To cache queries you have to go beyond that:
* enable query caching globally
* specify on the query that it's cachable

Even more, when you change any object which might affect the query result, the results are evicted from cache.
Example:
1) list all users --> need to load from database
2) lists all users --> will use cache
3) insert a new user -->invalidates the query cache for "list all users" query
4) lists all users --> needs to query the database again

This is all needed to have transactions work correctly, and use caches.
Hope this is useful to verify your cache usage: be sure to enable all options and to not invalidate the entry.

_________________
Sanne
http://in.relation.to/


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.