SpringMVC3.2.x + Hibernate4.2.x + ecache

附件是源码

pom.xml
————————————————


  1.  

SQL
——————————————————————–

web.xml
——————————————————

src/main/resources/applicationContext.xml
——————————————————————–


  1.  

JBPM5sh-servlet.xml
——————————

src/main/resources/ehcache.xml
——————————————————-

这个是缓存配置

src/main/resources/jdbc.properties
———————————————————
jdbc.driver=net.sf.log4jdbc.DriverSpy
jdbc.url=jdbc:log4jdbc:mysql://localhost:3306/jbpmtest?createDatabaseIfNotExist=true
#jdbc.driver=com.mysql.jdbc.Driver
#jdbc.url=jdbc:mysql://localhost:3306/jbpmtest?createDatabaseIfNotExist=true

jdbc.username=root
jdbc.password=root
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

src/main/resources/log4j.properties
—————————————————-
log4j.rootLogger=WARN, stdout
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L – %m%n

# log4jdbc
log4j.logger.jdbc.sqlonly=INFO
log4j.logger.jdbc.sqltiming=INFO
log4j.logger.jdbc.audit=OFF
log4j.logger.jdbc.resultset=OFF
log4j.logger.jdbc.connection=OFF

src/main/java/com/pandy/ssh4/domian/BasicDomian.java
————————————————————————————–

src/main/java/com/pandy/ssh4/domian/Table3.java
——————————————————

src/main/java/com/pandy/ssh4/dao/BasicDao.java
—————————————————————————-

src/main/java/com/pandy/ssh4/dao/impl/Table3Dao.java
—————————————————————-

注意,query.setCacheable(true);//设定使用缓存是设定了缓存

src/main/java/com/pandy/ssh4/service/SampleService.java
————————————————————-

src/main/java/com/pandy/ssh4/controller/TestController.java
————————————————-

src/main/webapp/index.jsp
————————————————–

src/main/webapp/views/success.jsp
—————————————

src/main/webapp/views/failure.jsp
——————————————–

http://localhost:8080/JBPM5sh/doTest.do
———————————————–OUTPUT
12:47:13,628  INFO sqlonly:236 – insert into TABLE3 (EMAIL, NAME, PASSWORD) values (‘panyongzheng@163.com’, ‘pandy’, NULL)
12:47:13,630  INFO sqltiming:357 – insert into TABLE3 (EMAIL, NAME, PASSWORD) values (‘panyongzheng@163.com’, ‘pandy’, NULL)  {executed in 0 msec}
12:47:13,638  WARN JdbcCoordinatorImpl:411 – HHH000387: ResultSet’s statement was not registered
—————————————-增加完成
12:47:13,887  INFO sqlonly:236 – select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_
12:47:13,888  INFO sqltiming:357 – select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_  {executed in 1 msec}
Table3 [id=13, name=pandy, password=null, email=panyongzheng@163.com]
验证完成
—————————————-修改完成
12:47:13,917  INFO sqlonly:236 – update TABLE3 set EMAIL=’panyongzheng@163.com’, NAME=’New Name’, PASSWORD=NULL where ID=13

12:47:13,918  INFO sqltiming:357 – update TABLE3 set EMAIL=’panyongzheng@163.com’, NAME=’New Name’, PASSWORD=NULL where ID=13
{executed in 1 msec}
12:47:13,920  INFO sqlonly:236 – select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_
12:47:13,921  INFO sqltiming:357 – select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_  {executed in 1 msec}
Table3 [id=13, name=New Name, password=null, email=panyongzheng@163.com]
验证完成
—————————————-删除完成 id=13
12:47:13,924  INFO sqlonly:236 – delete from TABLE3 where ID=13
12:47:13,925  INFO sqltiming:357 – delete from TABLE3 where ID=13  {executed in 0 msec}
12:47:13,926  INFO sqlonly:236 – select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_
12:47:13,927  INFO sqltiming:357 – select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_  {executed in 1 msec}
验证完成
—————————————-增加两个记录来测试缓存
12:47:14,021  INFO sqlonly:236 – insert into TABLE3 (EMAIL, NAME, PASSWORD) values (‘panyongzheng@163.com’, ‘pandy1’, NULL)

12:47:14,022  INFO sqltiming:357 – insert into TABLE3 (EMAIL, NAME, PASSWORD) values (‘panyongzheng@163.com’, ‘pandy1’, NULL)
{executed in 0 msec}
12:47:14,023  WARN JdbcCoordinatorImpl:411 – HHH000387: ResultSet’s statement was not registered
12:47:14,024  INFO sqlonly:236 – insert into TABLE3 (EMAIL, NAME, PASSWORD) values (‘panyongzheng@163.com’, ‘pandy2’, NULL)

12:47:14,025  INFO sqltiming:357 – insert into TABLE3 (EMAIL, NAME, PASSWORD) values (‘panyongzheng@163.com’, ‘pandy2’, NULL)
{executed in 0 msec}
12:47:14,026  WARN JdbcCoordinatorImpl:411 – HHH000387: ResultSet’s statement was not registered
—————————————-增加两个记录信息
12:47:14,028  INFO sqlonly:236 – select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_
12:47:14,029  INFO sqltiming:357 – select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_  {executed in 1 msec}
listAll-> Table3 [id=14, name=pandy1, password=null, email=panyongzheng@163.com]
listAll-> Table3 [id=15, name=pandy2, password=null, email=panyongzheng@163.com]
—————第一次查询——————–
12:47:14,103  INFO sqlonly:236 – select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_
12:47:14,104  INFO sqltiming:357 – select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_  {executed in 1 msec}
2
—————第二次查询——————–
2
—————缓存信息——————–
Statistics[start time=1368852423495,sessions opened=3,sessions closed=2,transactions=2,successful transactions=2,optimistic lock failures=0,flushes=3,connections obtained=3,statements prepared=10,statements closed=0,second level cache puts=2,second level cache hits=0,second level cache misses=0,entities loaded=2,entities updated=1,entities inserted=3,entities deleted=1,entities fetched=0,collections loaded=0,collections updated=0,collections removed=0,collections recreated=0,collections fetched=0,naturalId queries executed to database=0,naturalId cache puts=0,naturalId cache hits=0,naturalId cache misses=0,naturalId max query time=0,queries executed to database=5,query cache puts=1,query cache hits=1,query cache misses=1,update timestamps cache puts=7,update timestamps cache hits=1,update timestamps cache misses=0,max query time=12]
put:2
hit:0
miss:0

注意到第二次查询。不再查询数据库,就是缓存了。