spring整合hibernate+ehcache实现最简单的入门代码demo实例,对初学者很有帮助
学习如何在hibernate中配置二级缓存ehcache
项目截图:
运行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
猜你喜欢
- ssh整合extjs的项目实例
- ssh简单的整合实例
- spring项目整合ehcache和redis缓存实例
- maven整合ssm框架+EhCache搭建(eclipse可直接运行)
- SSH网站实例
- SSH整合开发入门小例子,适合java web开发初学者
- ssh框架(struts1+spring+hibernate)整合实现java网上商城项目源代码
- Spring4+Hibernate4+MySQL+Maven项目整合Java Web实例(Annotations+XML)
- spring整合ehcache的入门级别demo分享,通过junit来测试
- 整合好的SSH项目简单实例
- SSH学习之路-Spring整合Hibernate(两种配置其中一种完全抛弃Hibernate的核心配置文件直接定义在Spring核心配置文件中)
- ssh框架开发整合实现用户简单登陆demo,适合ssh初学者学习
- /
- /HibernateEHCacheExample
- /HibernateEHCacheExample/.classpath
- /HibernateEHCacheExample/.project
- /HibernateEHCacheExample/pom.xml
- /HibernateEHCacheExample/src
- /HibernateEHCacheExample/src/main
- /HibernateEHCacheExample/src/main/java
- /HibernateEHCacheExample/src/main/java/com
- /HibernateEHCacheExample/src/main/java/com/zuidaima
- /HibernateEHCacheExample/src/main/java/com/zuidaima/hibernate
- /HibernateEHCacheExample/src/main/java/com/zuidaima/hibernate/main
- /HibernateEHCacheExample/src/main/java/com/zuidaima/hibernate/model
- /HibernateEHCacheExample/src/main/java/com/zuidaima/hibernate/util
- /HibernateEHCacheExample/src/main/java/com/zuidaima/hibernate
- /HibernateEHCacheExample/src/main/java/com/zuidaima
- /HibernateEHCacheExample/src/main/java/com
- /HibernateEHCacheExample/src/main/resources
- /HibernateEHCacheExample/src/main/resources/hibernate.cfg.xml
- /HibernateEHCacheExample/src/main/resources/myehcache.xml
- /HibernateEHCacheExample/src/main/java
- /HibernateEHCacheExample/src/main
- /HibernateEHCacheExample