最代码官方的gravatar头像
最代码官方 2014-10-17 14:28:45

spring整合hibernate+ehcache实现最简单的入门代码demo实例,对初学者很有帮助

学习如何在hibernate中配置二级缓存ehcache

项目截图:

spring整合hibernate+ehcache实现最简单的入门代码demo实例,对初学者很有帮助

运行com.zuidaima.hibernate.main.HibernateEHCacheMain.java后输出:

Stats enabled=false
Stats enabled=true
***** 0 *****
Fetch Count=0
Second Level Hit Count=0
Second Level Miss Count=0
Second Level Put Count=0
Hibernate: select employee0_.emp_id as emp_id1_1_0_, employee0_.emp_name as emp_name2_1_0_, employee0_.emp_salary as emp_sala3_1_0_, address1_.emp_id as emp_id1_0_1_, address1_.address_line1 as address_2_0_1_, address1_.city as city3_0_1_, address1_.zipcode as zipcode4_0_1_ from EMPLOYEE employee0_ left outer join ADDRESS address1_ on employee0_.emp_id=address1_.emp_id where employee0_.emp_id=?
1:: Name=1, Zipcode=1
***** 1 *****
Fetch Count=1
Second Level Hit Count=0
Second Level Miss Count=1
Second Level Put Count=2
2:: Name=1, Zipcode=1
***** 2 *****
Fetch Count=1
Second Level Hit Count=0
Second Level Miss Count=1
Second Level Put Count=2
Hibernate: select employee0_.emp_id as emp_id1_1_0_, employee0_.emp_name as emp_name2_1_0_, employee0_.emp_salary as emp_sala3_1_0_, address1_.emp_id as emp_id1_0_1_, address1_.address_line1 as address_2_0_1_, address1_.city as city3_0_1_, address1_.zipcode as zipcode4_0_1_ from EMPLOYEE employee0_ left outer join ADDRESS address1_ on employee0_.emp_id=address1_.emp_id where employee0_.emp_id=?
3:: Name=1, Zipcode=1
***** 3 *****
Fetch Count=2
Second Level Hit Count=0
Second Level Miss Count=2
Second Level Put Count=3
Hibernate: select employee0_.emp_id as emp_id1_1_0_, employee0_.emp_name as emp_name2_1_0_, employee0_.emp_salary as emp_sala3_1_0_, address1_.emp_id as emp_id1_0_1_, address1_.address_line1 as address_2_0_1_, address1_.city as city3_0_1_, address1_.zipcode as zipcode4_0_1_ from EMPLOYEE employee0_ left outer join ADDRESS address1_ on employee0_.emp_id=address1_.emp_id where employee0_.emp_id=?
4:: Name=3, Zipcode=3
***** 4 *****
Fetch Count=3
Second Level Hit Count=0
Second Level Miss Count=3
Second Level Put Count=5
Hibernate: select employee0_.emp_id as emp_id1_1_0_, employee0_.emp_name as emp_name2_1_0_, employee0_.emp_salary as emp_sala3_1_0_, address1_.emp_id as emp_id1_0_1_, address1_.address_line1 as address_2_0_1_, address1_.city as city3_0_1_, address1_.zipcode as zipcode4_0_1_ from EMPLOYEE employee0_ left outer join ADDRESS address1_ on employee0_.emp_id=address1_.emp_id where employee0_.emp_id=?
5:: Name=1, Zipcode=1
***** 5 *****
Fetch Count=4
Second Level Hit Count=0
Second Level Miss Count=4
Second Level Put Count=6

数据库建库语句:

create database test;

use test;

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `address`
-- ----------------------------
DROP TABLE IF EXISTS `address`;
CREATE TABLE `address` (
  `emp_id` bigint(20) NOT NULL,
  `address_line1` varchar(255) DEFAULT NULL,
  `city` varchar(255) DEFAULT NULL,
  `zipcode` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`emp_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of address
-- ----------------------------
INSERT INTO address VALUES ('1', '1', '1', '1');
INSERT INTO address VALUES ('3', '3', '3', '3');


-- ----------------------------
-- Records of article
-- ----------------------------
INSERT INTO article VALUES ('1', 'test', 'test', null);

-- ----------------------------
-- Table structure for `employee`
-- ----------------------------
DROP TABLE IF EXISTS `employee`;
CREATE TABLE `employee` (
  `emp_id` bigint(20) NOT NULL AUTO_INCREMENT,
  `emp_name` varchar(255) DEFAULT NULL,
  `emp_salary` double DEFAULT NULL,
  PRIMARY KEY (`emp_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of employee
-- ----------------------------
INSERT INTO employee VALUES ('1', '1', '1');
INSERT INTO employee VALUES ('3', '3', '3');

参考地址:http://www.journaldev.com/2980/hibernate-ehcache-second-level-caching-example-tutorial


打赏

文件名:HibernateEHCacheExample.rar,文件大小:6.283K 下载
最代码最近下载分享源代码列表最近下载
wycccc  LV1 2019年6月8日
ORO4444  LV12 2019年3月20日
wcy071213  LV27 2018年6月2日
ganfeng  LV2 2018年5月11日
88204879  LV2 2018年3月28日
xiaoyu888  LV5 2018年3月21日
346058210  LV6 2018年1月11日
zmqzmq  LV1 2017年3月23日
yedk123  LV1 2017年2月16日
纸天才  LV1 2017年2月15日
最代码最近浏览分享源代码列表最近浏览
y_x_happy  LV4 6月25日
wordtong  LV3 2021年6月27日
mudingc木钉  LV30 2021年6月11日
hashjaaa  LV4 2021年1月7日
MARTIN66666  LV1 2020年12月26日
北巷枫  LV9 2020年12月23日
banzhenghao  LV7 2020年11月23日
fmmjjj  LV3 2020年6月26日
jimmyke  LV2 2020年6月16日
IkunLYY  LV4 2020年6月14日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友