问题描述
我正在从我的EJB Bean查询数据库,这是DAO,我的查询样式如下: public List findDirectories()
{
allDirectories = getHibernateTemplate()。find(from+ Directory.class.getName()+
d order by upper(d.name););
return allDirectories;
}
我想缓存这个结果,我该怎么做,有没有我也可以参考的例子。
所有我想做的是在我的 EBJ Bean
中,缓存上述查询的结果集,所以下次当页面刷新时,我去从缓存中获取结果然后从数据库中获取。
更新:使用较旧版本的 EJB
,因此可以使用酷功能
EJB3
使用无状态会话EJB来缓存和管理不经常更改的数据。如果数据符合所有期望,则有时更新EJB。
Java EE 6提供了一种稍微不同的技术,单例bean:。
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
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.
这篇关于如何在EJB bean中设置缓存,其中使用hibernate模板查询数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!