aspose file tools*
The moose likes Object Relational Mapping and the fly likes how to retrieve data from a cache in hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "how to retrieve data from a cache in hibernate" Watch "how to retrieve data from a cache in hibernate" New topic
Author

how to retrieve data from a cache in hibernate

Saumya Nair
Ranch Hand

Joined: Apr 25, 2006
Posts: 34
hiiiii all,

i have cached a tables data using EHCacheprovider.How can i retrieve the cached data ??? I have written the code shown below. I am able to get the size of the cache but when i pass the id in the get() method it return me the data enclosed in curly brackets... How can i get the data from this format ???

CODE :
------
Map userList = new HashMap();
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
userList = sessionFactory.getStatistics().getSecondLevelCacheStatistics ("user").getEntries();

System.out.println("-----------*****" + userList.size() + "****-----------");
System.out.println("---------" + userList.get(id) + "----------");



OUTPUT :
--------
Item{version=null,freshTimestamp=4698877591896064

(earlier i used to get all the values vth the name as specified in the hbm.xml file along with the version n lazy property.. I dint make any change to the code... but all of a sudden started getting this result.Can anyone explain why ???)
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

All you are seeing is the output of the toString() method for that object. Override it to display whatever you like if that's what you want to do.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
why do you want to access the 2nd level cache directly ?
if everything is configured properly then hibernate will not hit the DB and return the cached object instead.


pascal
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
btw: you must have made a change... otherwise system would still behave as it did befor :-)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to retrieve data from a cache in hibernate
 
Similar Threads
Accessing an element of a list, whose position is given as URL parameter
Caching in an EJB container
submitting data to database
No getter method for property name of bean userList
Problem with Hibernate Cache