`
mixer_a
  • 浏览: 356875 次
社区版块
存档分类
最新评论

spring + hibernate 二级缓存 ehcache

阅读更多

1:配置spring 文件

在sessionfactiory的bean中加上如下配置

Xml代码
  1. < prop   key = " hibernate .show_sql" > true </ prop >   
  2. 打开二级缓存                 
  3. < prop   key = " hibernate .cache.use_second_level_cache" > true </ prop >   
  4. 指定二级缓存的外部程序我用的是ECACHE   
  5. < prop key = " hibernate .cache.provider_class" > org.hibernate .cache.EhCacheProvider </ prop >     
  6. 打开hibernate 的查询缓存   
  7. < prop   key = " hibernate .cache.use_query_cache" > true </ prop >   

2配置要使用缓存的实体

Xml代码

< hibernate -mapping >   

     < class   name = "com.tjsinfo.tjsoa.mail.vo.TjsEmailFolder"   table = "TjsEmailFolder"   schema = "tjsoadba"   catalog = "TJSOA" >   

关键是这里指定缓存的策略一般用读写就可以了,如果数据从不变化可以用只读   

         < cache   usage = "read-write" > </ cache >   

         < id   name = "folderId"   type = "java.lang.Integer" >   

             < column   name = "Folder_id"   />   

             < generator   class = "native"   />   

         </ id >

    </ class >   

</ hibernate -mapping >

3定义ehcache.xml文件

Xml代码

< ehcache >   

     < diskStore   path = "java.io.tmpdir"></ diskStore>

<defaultCache maxElementsInMemory="10000" eternal="false"
   timeToIdleSeconds="120" timeToLiveSeconds="120"
   overflowToDisk="false" /></ehcache>

4执行相应的HQL语句,应当是第一次执行有SQL而第二次没有可是我试了一下还是有SQL说明查询缓存没用。我晕。

后来发现应当在调用查询的方法中的spring  hibernate 模板设置打开查询缓存。

Java代码

public   List selectHql(String hql) {   

         // TODO Auto-generated method stub    

        getHibernateTemplate().setCacheQueries( true );   

         return   getHibernateTemplate().find(hql);  

4
1
分享到:
评论

相关推荐

    springmvc4+spring4+hibernate5.1.3+二级缓存ehcache+fastjson配置

    Ehcache是Hibernate的一个可选二级缓存插件,用于存储数据库查询结果,减少对数据库的直接访问。当相同的数据再次被请求时,可以从缓存中快速获取,提高系统响应速度。在不使用缓存的情况下,可以通过配置关闭。 5...

    Struts2+Spring+Hibernate+Ehcache+AJAX+JQuery+Oracle 框架集成用户登录注册Demo工程

    1.通过google ehcache-spring-annotatios.jar自动注解方式实现整合Spring+Ehcache。 2.Action里通过struts2-spring-plugin.jar插件自动根据名字注入。 3.Ajax无刷新异步调用Struts2,返回Json数据,以用户注册为例。...

    Spring集成的Hibernate配置二级缓存

    以EhCache为例,我们需要在项目中引入ehcache-core或ehcache的依赖,并在Hibernate配置文件(hibernate.cfg.xml或persistence.xml)中启用二级缓存,添加如下配置: ```xml &lt;property name="hibernate.cache.use_...

    spring+springmvc+hibernate+ehcache JavaWeb后台框架

    spring+springmvc+hibernate+ehcache JavaWeb后台框架,不仅提高了开发程序的速度,且其中还是用到hibernate和ehcache缓存的使用,加快了程序运行的数据,该框架亲测好用。值得注意的是该种框架现在还算是用的比较多...

    Spring4+Hibernate4二级缓存实例源码

    通过这个"Spring4+Hibernate4二级缓存实例源码",你可以学习到如何在实际项目中结合Spring和Hibernate实现二级缓存,提高应用的运行效率。同时,深入理解缓存的工作原理和最佳实践,对于优化系统的性能和架构有着...

    在Spring+Hibernate集成环境中使用EhCache缓存

    然后,我们需要在Hibernate的配置中启用二级缓存,并指定使用EhCache。在`hibernate.cfg.xml`文件中添加以下配置: ```xml &lt;property name="hibernate.cache.use_second_level_cache"&gt;true &lt;property name="...

    Spring+Hibernate+ehcache整合

    Ehcache作为二级缓存被集成到Hibernate中,可以通过设置`&lt;property name="hibernate.cache.provider_class"&gt;net.sf.ehcache.hibernate.EhCacheProvider&lt;/property&gt;`来启用。 3. **Ehcache配置**:`ehcache.xml`文件...

    ssh,struts+hibernate+spring+ehcache集成

    例如,为了使用Ehcache,需要在Spring配置文件中添加Ehcache的相关bean,然后在Hibernate的SessionFactory配置中启用二级缓存。此外,还需要在Struts的Action中调用由Spring管理的业务服务,这些服务通常会利用...

    SpringMVC+hibernate+spring+shiro+Ehcache所需jar包

    这个压缩包"SpringMVC+hibernate+spring+shiro+Ehcache所需jar包"提供了搭建基于SpringMVC、Spring 4.2、Hibernate 4.3、Shiro 1.2.4和Ehcache 2.0的基础组件,这些都是Java开发中非常流行和实用的工具。接下来,...

    springmvc+spring+hibernate环境

    Hibernate的二级缓存可以提高数据读取效率,常见的缓存提供商有EhCache和Redis。 在"springmvc+spring+hibernate环境"中,配置文件通常会包括Spring的配置文件(如applicationContext.xml)、Spring MVC的配置文件...

    基于Struts2+Spring+Hibernate+MySql的注册登录系统.zip

    EhCache是Hibernate的二级缓存技术之一,它能够提高数据库的访问效率。当频繁访问的数据被缓存后,可以直接从内存中获取,减少了对数据库的查询次数,从而提高了系统的响应速度。在SSH系统中,EhCache的集成可以减轻...

    struts2+spring+hibernate集成例子(包含所有jar包,ehcache二级缓存)

    struts2+spring+hibernate集成例子,包含所有jar包,ehcache二级缓存,mysql数据,需要自己创建

    Hibernate4二级缓存Ehcache案例

    在这个“Hibernate4二级缓存Ehcache案例”中,我们将深入探讨如何利用Ehcache作为Hibernate的二级缓存提供商,以提升应用性能。 首先,我们需要了解什么是二级缓存。一级缓存是Hibernate Session级别的缓存,每个...

    spring+springMVC+hibernate+cxf+定时器+ehcache个人整合

    这里我们关注的是一个基于Spring、SpringMVC、Hibernate、CXF、Quartz定时器和Ehcache的整合项目。这个项目结合了这些技术,以实现一个高效、灵活且可扩展的企业级应用。下面将详细介绍每个组件及其在整体架构中的...

    spring3+hibernate4+struts2+dbcp+mysql+json+ehcache+dom4j 合集包

    Spring负责整体的流程控制和依赖注入,Hibernate处理数据持久化,Struts 2处理Web请求,DBCP管理数据库连接,MySQL提供数据存储,JSON用于数据交换,Ehcache实现缓存机制,DOM4J处理XML文档。这个资源包为开发者提供...

    Spring+MyBatis/Hibernate+Ehcache+Maven的Demo Web项目(稳定版)

    2.Hibernate几个级别缓存对比。见DaoImpl类 3.Ehcache方法缓存及页面缓存。见applicationContext-cache.xml及web.xml的pageEhCacheFilter 4.MyBatis+Maven代码生成工具。见bin目录 5.作为项目或者技术研究的基础架构...

    配置Spring+hibernate使用ehcache作为second-levelcache.docx

    Ehcache 是一个开源的缓存框架,提供了一个高性能的缓存解决方案,可以与 Hibernate 和 Spring 整合使用,以提高应用程序的性能。 缓存的重要性 在 Web 应用程序中,数据库访问是性能瓶颈之一。数据库访问需要消耗...

    struts1.x+spring+hibernate集成例子(包含所有jar包,ehcache二级缓存)

    Ehcache 的引入是为了实现二级缓存,提高数据读取速度。它可以在内存中存储常用数据,减少对数据库的访问。Hibernate 可以与 Ehcache 集成,将频繁查询的结果缓存起来,当相同的查询再次发生时,直接从缓存中获取,...

    spring boot 使用jsp 集成hibernate+shiro+ehcache项目分享

    【Spring Boot 使用 JSP 集成 Hibernate+Shiro+Ehcache 项目详解】 Spring Boot 是一个基于 Spring 框架的高度集成了多种技术的开发工具,它简化了配置过程,使得开发人员能够快速构建可运行的应用程序。在这个项目...

    Maven项目Spring4+Hibernate4+shiro+Ehcache项目集成

    在本项目中,我们主要探讨的是一个基于Maven构建的Java Web应用,它整合了Spring 4、Hibernate 4、Apache Shiro以及Ehcache等多个关键框架,旨在实现用户角色菜单管理的功能。以下是对这些技术及其集成应用的详细...

Global site tag (gtag.js) - Google Analytics