• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to retrieve data from a cache in hibernate

 
Saumya Nair
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
btw: you must have made a change... otherwise system would still behave as it did befor :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic