b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

Hibernate + EhCache配置辅助缓存

电脑杂谈  发布时间:2020-04-01 01:09:34  来源:网络整理

hibernate注解_hibernate二级缓存注解_hibernate二级缓存注解

从:

本文主要讨论Hibernate + EhCache配置辅助缓存的基本用法. 它主要分为以下两个方面:

(有关EhCache的基本介绍hibernate二级缓存注解,请参阅: )

[一]缓存的多种配置方法

Javabean缓存配置分为三种类型hibernate二级缓存注解,如下所述:

(1).Bean配置方法: @Cache(用法= CacheConcurrencyStrategy.READ_WRITE)

(2).hibernate.cfg.xml标记配置方法:

(3). 映射文件* .hb.xml中的标记配置方法: <缓存用法=“ />

hibernate注解_hibernate二级缓存注解_hibernate二级缓存注解

1. classpath: ehcahce.xml配置文件如下:

Xml代码收藏代码

<? xmlversion =“ 1.0”编码=“ UTF-8”?> <ehcachexmlns: xsi =“ http://www.w3.org/2001/XMLSchema-instance” xsi: noNamespaceSchemaLocation =“ ehcache. xsd” updateCheck =“ true”监视=“自动检测” dynamicConfig =“ true”>

休眠. 缓存. StandardQueryCache“ maxElementsInMemory =” 5“ eternal =” false“ timeToLiveSeconds =” 120“ overflowToDisk =” true“ />

2.hibernate配置文件: hibernate.cfg.xml

Xml代码收藏代码

<! DOCTYPEhibernate-configurationPUBLIC“-// Hibernate / HibernateConfigurationDTD // EN”“ http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”> oracle. jdbc. 司机. OracleDriver jdbc: oracle: 薄: @localhost: 1521: ora11g mytest 111111 组织.

休眠. 方言. Oracle9Dialect <属性名称=“ connection.useUnicode”>正确 <属性名称=“连接.characterEncoding”> UTF-8 <属性名称=“ connection.SetBigStringTryClob”>正确 < propertyname =“ connection.pool_size”> 10 10 true false < / property> 线程

hibernate二级缓存注解_hibernate注解_hibernate二级缓存注解

自动“>更新 <!-Hibernate3.3andhigher-> <!-<属性名=” hibernate. 缓存. 区域. factory_class“> net.sf.ehcache.hibernate.EhCacheRegionFactory net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory -> <!-hibernate 3.0-3.2cacheconfig-> <!- net.sf.ehcache.hibernate.EhCacheProvider ->

缓存. provider_class“> net.sf.ehcache.hibernate.SingletonEhCacheProvider <!-EnableSecond-LevelCacheandQueryCacheSettings-> <!-注释配置->

EhBlogTopic2“ /> <!-映射文件-> <!-class-cacheconfig->

3. 相关的Javabean代码片段如下:

(1).hibernate.cfg.xml已配置标记: EhBlogTopic.java:

Java代码收藏代码

/ *** @博客* @ authorMichael * / @实体@ Table(名称=“ MY_TB_EH_BLOG_TOPIC”)publicclassEhBlogTopicimplementsSerializable {/ *** serialVersionUID * / privatestaticfinallongserialVersionUID = -570936907944909799L; privateIntegerid; privateStringuserId ;;省略)

(2).bean用注释配置缓存: EhBlogTopic2.java

hibernate注解_hibernate二级缓存注解_hibernate二级缓存注解

Java代码收藏代码

/ *** @博客* @ authorMichael * / @实体@ Table(名称=“ MY_TB_EH_BLOG_TOPIC2”)@缓存(用法= CacheConcurrencyStrategy.READ_WRITE)publicclassEhBlogTopic2implementsSerializable {//与EhBlogTopic //其他省略}

(3). 在映射文件* .hb.xml中添加缓存标记: EhBlogTopic3.java

Java代码收藏代码

/ *** @博客* @ authorMichael * / publicclassEhBlogTopic3implementsSerializable {//属性与EhBlogTopic相同//其他省略}

tb_EhBlogTopic3.hb.xml

Xml代码收藏代码

<? xmlversion =“ 1.0”?> <! DOCTYPEhibernate-mappingPUBLIC“-// Hibernate / HibernateMappingDTD2.0 // ZH”“ http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd”>

hibernate二级缓存注解_hibernate注解_hibernate二级缓存注解

(4). 未配置缓存的Bean: EhUserInfo.java

Java代码收藏代码

/ *** @博客* @ authorMichael * / @实体@表(名称=“ MY_TB_EH_USER_INFO”)publicclassEhUserInfoimplementsSerializable {/ *** serialVersionUID * / privatestaticfinallongserialVersionUID = 930384253681681679239L; privateIntegerid; privateStringuserInfo; privateStringuserName; privateStringuserName; @returntheid * / @ ID @ GeneratedValue @ Column(名称=“ ID”)publicIntegergetId(){returnid;} //其他省略. . . }

4. 测试运行代码如下:

Java代码收藏代码

包裹迈克尔. 缓存. ehcache. 冬眠importjava. 实用程序. 清单; importmichael. 冬眠. 大串甲骨文. BigStrBlob; importnet. SF ehcache. 缓存; importnet. SF ehcache. CacheManager; importorg. 冬眠. 查询; importorg. 冬眠. 会议; importorg. 冬眠. SessionFactory; importorg. 冬眠. 交易; importorg. 冬眠. cfg. AnnotationConfiguration; importorg. 冬眠. cfg. 组态; / **** @博客* @ authorMichael * / publicclassTestEhcacheHibernate {/ *** @ paramargs * / @ SuppressWarnings(“ unchecked”)publicstaticvoidmain(String [] args){testMulitConfigMethod();} / ***测试更多方式配置缓存* / publicstaticvoidtestMulitConfigMethod(){SessionFactorysessionFactory = null;尝试{系统.

退出. println(“ ehcache-hibernateTest ...”); Configurationconfig = newAnnotationConfiguration(). 配置(“ michael / cache / ehcache / hibernate / hibernate.cfg.xml”);系统. 出来. println(“ hibernateconfigsuccessful: ” + config); sessionFactory =配置. buildSessionFactory(); Transactionta = null;尝试{Sessionsession = sessionFactory. getCurrentSession(); ta =会话. beginTransaction();} catch(Exceptione){e. printStackTrace(); ta. rollback();}字符串[] cacheNames = CacheManager. getInstance(). getCacheNames();系统. 出来. println(“ cached keycacheNameslength: =” + cacheNames.

length +“详细列表如下: ”); for(Stringname: cacheNames){系统. 出来. println(“ name: =” + name);}} catch(Exceptione){e. printStackTrace();}系统. 出来. println(“ ehcache-hibernateTestend. ”);}}

结果如下:

ehcache-休眠测试...

hibernate配置成功: org.hibernate.cfg.AnnotationConfiguration@193c0cf


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-159473-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      热点图片
      拼命载入中...