I am trying to use EHcache as second level cache with Hibernate. But I am getting into some questions, which are affecting my decision to use it. I have already enabled second level cache by including hibernate.cache.provider_class net.sf.hibernate.cache.EhCacheProvider property in Hibernate.prperties file. I have also included ehcache.xml and <cache> element in my mapping file.
I am giving snippet of code below that I am using to store user defined objects in second level cache.
Session session = sessionFactory.openSession;
Transaction tx = session.beginTransaction();
List xc = session.find("from sc.data.address");
tx.commit();
session.close();
This will put all the addresses from database to cache. Now suppose I want to retrieve back all of my objects back from cache, there is no method which can give me all my address objects back.
I am using following method to get list of all the keys.
List keyList = cache.getKeys();
This method gives you list of Keys of all the objects in Cache and then you have to loop through this list to get Element Object back and not address object back.
1. How can I get all of my address objects back from cache in one method call so that I can use them.
2. The object that you get back from cache by using cache.get(Key) is an Element object and not the object (address) that I put into cache.
3. DO I need to reconstruct my address object from Element object that I get back from Cache?
4. Are there any concrete examples where EHcache is being used as second level cache, where we are putting multiple database rows in cache and then getting all of them at once.
Can somebody please give me an urgent reply?
Thanks
|