第一步:
将hibernate目录下/lib/optional/ehcache下的jar导入你的工程备用
第二步:
在hibernate.cfg.xml文件里面加上如下的配置
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/waterfall_web?useUnicode=true&characterEncoding=UTF-8</property>
<property name="connection.username">qiang.xue</property>
<property name="connection.password"></property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
[color=red]<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>[/color]
<mapping resource="com/model/channel.hbm.xml"/>
</session-factory>
</hibernate-configuration>
第三步:
在src目录下新建ehcache.xml文件,内容如下:
<ehcache>
<diskStore path = "c:/cache"/>
<defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="true"/>
</ehcache>
第四步:
修改*.hbm.xml文件,如下:
<class name = "Product" table = "product" lazy="true">
[color=red]<cache usage="read-write"/>[/color]
<id name="id"></id>
<property name="taobaoId" column="pid"></property>
</class>
至此hibernate的二级缓存配置结束
将hibernate目录下/lib/optional/ehcache下的jar导入你的工程备用
第二步:
在hibernate.cfg.xml文件里面加上如下的配置
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/waterfall_web?useUnicode=true&characterEncoding=UTF-8</property>
<property name="connection.username">qiang.xue</property>
<property name="connection.password"></property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
[color=red]<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>[/color]
<mapping resource="com/model/channel.hbm.xml"/>
</session-factory>
</hibernate-configuration>
第三步:
在src目录下新建ehcache.xml文件,内容如下:
<ehcache>
<diskStore path = "c:/cache"/>
<defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="true"/>
</ehcache>
第四步:
修改*.hbm.xml文件,如下:
<class name = "Product" table = "product" lazy="true">
[color=red]<cache usage="read-write"/>[/color]
<id name="id"></id>
<property name="taobaoId" column="pid"></property>
</class>
至此hibernate的二级缓存配置结束