How to set caching in EJB bean where am querying d

2019-07-04 01:35发布

I am querying database from my EJB Bean, which is DAO, my query look's like:

public List findDirectories()
{
  allDirectories = getHibernateTemplate().find("from " + Directory.class.getName() +
        " d order by upper(d.name)";);
  return allDirectories;
}

I want to cache this results, how can i do that, is there an example which i can refer too. All i want to do is in my EBJ Bean, cache the resultset of above query so next time when page refreshes then i go and get results from the cache rather then getting from database.

Update: Am using older versions of EJB and so can use cool features of EJB3

1条回答
Deceive 欺骗
2楼-- · 2019-07-04 02:07

The general idea here is to use stateless session EJBs to cache and manage infrequently changed data. Update the EJB occasionally if data, against all expectations, changes.

Java EE 6 provides a slightly different technique, singleton beans: http://java.sun.com/developer/technicalArticles/JavaEE/JavaEE6Overview_Part3.html.

查看更多
登录 后发表回答