package easyStart.Run; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import easyStart.Entity.User; public class QuickStart { public static void main(String[] args) { final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build(); SessionFactory sessionFactory = null; try { sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); } catch (Exception e) { StandardServiceRegistryBuilder.destroy(registry); } Session session = sessionFactory.openSession(); session.beginTransaction(); // 处理事务 Begin User user1 = session.get(User.class, 1); User user2 = session.get(User.class, 1); System.out.println(user1==user2); // 处理事务 End session.getTransaction().commit(); session.close(); sessionFactory.close(); } }
问题:控制台输出结果是TRUE 还是 FALSE?
1 六月 11, 2018 4:59:57 下午 org.hibernate.Version logVersion 2 INFO: HHH000412: Hibernate Core {5.0.1.Final} 3 六月 11, 2018 4:59:57 下午 org.hibernate.cfg.Environment <clinit> 4 INFO: HHH000206: hibernate.properties not found 5 六月 11, 2018 4:59:57 下午 org.hibernate.cfg.Environment buildBytecodeProvider 6 INFO: HHH000021: Bytecode provider name : javassist 7 六月 11, 2018 4:59:57 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit> 8 INFO: HCANN000001: Hibernate Commons Annotations {5.0.0.Final} 9 六月 11, 2018 4:59:57 下午 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity 10 WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead. Support for obsolete DTD/XSD namespaces may be removed at any time. 11 六月 11, 2018 4:59:58 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 12 WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!) 13 六月 11, 2018 4:59:58 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 14 INFO: HHH000401: using driver [com.mysql.cj.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/ssh?serverTimezone=GMT&useSSL=false] 15 六月 11, 2018 4:59:58 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 16 INFO: HHH000046: Connection properties: {user=root, password=****} 17 六月 11, 2018 4:59:58 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 18 INFO: HHH000006: Autocommit mode: false 19 六月 11, 2018 4:59:58 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 20 INFO: HHH000115: Hibernate connection pool size: 20 (min=1) 21 六月 11, 2018 4:59:58 下午 org.hibernate.dialect.Dialect <init> 22 INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect 23 六月 11, 2018 4:59:58 下午 org.hibernate.boot.model.source.internal.hbm.ModelBinder bindProperty 24 WARN: HHH90000003: Use of DOM4J entity-mode is considered deprecated 25 六月 11, 2018 4:59:58 下午 org.hibernate.boot.model.source.internal.hbm.ModelBinder bindProperty 26 WARN: HHH90000003: Use of DOM4J entity-mode is considered deprecated 27 六月 11, 2018 4:59:58 下午 org.hibernate.boot.model.source.internal.hbm.ModelBinder bindProperty 28 WARN: HHH90000003: Use of DOM4J entity-mode is considered deprecated 29 六月 11, 2018 4:59:59 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute 30 INFO: HHH000228: Running hbm2ddl schema update 31 Hibernate: 32 select 33 user0_.ID as ID1_0_0_, 34 user0_.NAME as NAME2_0_0_, 35 user0_.ADDRESS as ADDRESS3_0_0_ 36 from 37 USER user0_ 38 where 39 user0_.ID=? 40 true 41 六月 11, 2018 4:59:59 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop 42 INFO: HHH000030: Cleaning up connection pool [jdbc:mysql://localhost:3306/ssh?serverTimezone=GMT&useSSL=false]
由运行后日志输出可以看出,查询语句仅仅执行了1条!也就是说session的get方法第一次执行了SQL查询,第二次是取得第一次查询的缓存!
而且结果输出TRUE,user1==user2!
session.get方法进行查询,如果查询不到结果返回NULL;
session.load方法进行查询,如果查询不到结果抛出异常;
session.flush();会发起一条update语句;当事务提交的时候,强制使得数据库中的数据和缓存中的数据一致!
1 package easyStart.Run; 2 3 import org.hibernate.Session; 4 import org.hibernate.SessionFactory; 5 import org.hibernate.boot.MetadataSources; 6 import org.hibernate.boot.registry.StandardServiceRegistry; 7 import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 8 9 import easyStart.Entity.User; 10 11 public class QuickStart { 12 13 public static void main(String[] args) { 14 15 final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build(); 16 SessionFactory sessionFactory = null; 17 try { 18 sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); 19 } catch (Exception e) { 20 StandardServiceRegistryBuilder.destroy(registry); 21 } 22 23 Session session = sessionFactory.openSession(); 24 session.beginTransaction(); 25 // 处理事务 Begin 26 User user = session.load(User.class, 2); 27 user.setAddress("JangSu-ChangZhou"); 28 session.flush(); 29 // 处理事务 End 30 session.getTransaction().commit(); 31 session.close(); 32 sessionFactory.close(); 33 } 34 35 }
执行后,结果:
1 六月 11, 2018 5:16:50 下午 org.hibernate.Version logVersion 2 INFO: HHH000412: Hibernate Core {5.0.1.Final} 3 六月 11, 2018 5:16:50 下午 org.hibernate.cfg.Environment <clinit> 4 INFO: HHH000206: hibernate.properties not found 5 六月 11, 2018 5:16:50 下午 org.hibernate.cfg.Environment buildBytecodeProvider 6 INFO: HHH000021: Bytecode provider name : javassist 7 六月 11, 2018 5:16:51 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit> 8 INFO: HCANN000001: Hibernate Commons Annotations {5.0.0.Final} 9 六月 11, 2018 5:16:51 下午 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity 10 WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead. Support for obsolete DTD/XSD namespaces may be removed at any time. 11 六月 11, 2018 5:16:52 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 12 WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!) 13 六月 11, 2018 5:16:52 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 14 INFO: HHH000401: using driver [com.mysql.cj.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/ssh?serverTimezone=GMT&useSSL=false] 15 六月 11, 2018 5:16:52 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 16 INFO: HHH000046: Connection properties: {user=root, password=****} 17 六月 11, 2018 5:16:52 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 18 INFO: HHH000006: Autocommit mode: false 19 六月 11, 2018 5:16:52 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 20 INFO: HHH000115: Hibernate connection pool size: 20 (min=1) 21 六月 11, 2018 5:16:52 下午 org.hibernate.dialect.Dialect <init> 22 INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect 23 六月 11, 2018 5:16:52 下午 org.hibernate.boot.model.source.internal.hbm.ModelBinder bindProperty 24 WARN: HHH90000003: Use of DOM4J entity-mode is considered deprecated 25 六月 11, 2018 5:16:52 下午 org.hibernate.boot.model.source.internal.hbm.ModelBinder bindProperty 26 WARN: HHH90000003: Use of DOM4J entity-mode is considered deprecated 27 六月 11, 2018 5:16:52 下午 org.hibernate.boot.model.source.internal.hbm.ModelBinder bindProperty 28 WARN: HHH90000003: Use of DOM4J entity-mode is considered deprecated 29 六月 11, 2018 5:16:52 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute 30 INFO: HHH000228: Running hbm2ddl schema update 31 Hibernate: 32 select 33 user0_.ID as ID1_0_0_, 34 user0_.NAME as NAME2_0_0_, 35 user0_.ADDRESS as ADDRESS3_0_0_ 36 from 37 USER user0_ 38 where 39 user0_.ID=? 40 Hibernate: 41 update 42 USER 43 set 44 NAME=?, 45 ADDRESS=? 46 where 47 ID=? 48 六月 11, 2018 5:16:53 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop 49 INFO: HHH000030: Cleaning up connection pool [jdbc:mysql://localhost:3306/ssh?serverTimezone=GMT&useSSL=false]
可以看出当user.setAddress("JangSu-ChangZhou");执行了过后,影响了缓存中的内容,然后session.flush();函数强制更新了数据库,导致了数据库中的数据发生了变化!
注意了:session.flush();会发起一条update语句;但是还不会提交事务,只有事务被提交了,才会改变数据库的语句;
refresh()方法:他会强制发出一条SELECT语句,与缓存数据比较,如有不同,强制更新缓存使其与数据库一致!
1 package easyStart.Run; 2 3 import org.hibernate.Session; 4 import org.hibernate.SessionFactory; 5 import org.hibernate.boot.MetadataSources; 6 import org.hibernate.boot.registry.StandardServiceRegistry; 7 import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 8 9 import easyStart.Entity.User; 10 11 public class QuickStart { 12 13 public static void main(String[] args) { 14 15 final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build(); 16 SessionFactory sessionFactory = null; 17 try { 18 sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); 19 } catch (Exception e) { 20 StandardServiceRegistryBuilder.destroy(registry); 21 } 22 23 Session session = sessionFactory.openSession(); 24 session.beginTransaction(); 25 // 处理事务 Begin 26 User user = session.load(User.class, 2); 27 user.setAddress("JangSu-NanJing"); 28 System.out.println(user); 29 session.refresh(user); 30 System.out.println(user); 31 // 处理事务 End 32 session.getTransaction().commit(); 33 session.close(); 34 sessionFactory.close(); 35 } 36 37 }
1 六月 11, 2018 5:36:37 下午 org.hibernate.Version logVersion 2 INFO: HHH000412: Hibernate Core {5.0.1.Final} 3 六月 11, 2018 5:36:37 下午 org.hibernate.cfg.Environment <clinit> 4 INFO: HHH000206: hibernate.properties not found 5 六月 11, 2018 5:36:37 下午 org.hibernate.cfg.Environment buildBytecodeProvider 6 INFO: HHH000021: Bytecode provider name : javassist 7 六月 11, 2018 5:36:37 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit> 8 INFO: HCANN000001: Hibernate Commons Annotations {5.0.0.Final} 9 六月 11, 2018 5:36:37 下午 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity 10 WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead. Support for obsolete DTD/XSD namespaces may be removed at any time. 11 六月 11, 2018 5:36:38 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 12 WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!) 13 六月 11, 2018 5:36:38 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 14 INFO: HHH000401: using driver [com.mysql.cj.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/ssh?serverTimezone=GMT&useSSL=false] 15 六月 11, 2018 5:36:38 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 16 INFO: HHH000046: Connection properties: {user=root, password=****} 17 六月 11, 2018 5:36:38 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 18 INFO: HHH000006: Autocommit mode: false 19 六月 11, 2018 5:36:38 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 20 INFO: HHH000115: Hibernate connection pool size: 20 (min=1) 21 六月 11, 2018 5:36:39 下午 org.hibernate.dialect.Dialect <init> 22 INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect 23 六月 11, 2018 5:36:39 下午 org.hibernate.boot.model.source.internal.hbm.ModelBinder bindProperty 24 WARN: HHH90000003: Use of DOM4J entity-mode is considered deprecated 25 六月 11, 2018 5:36:39 下午 org.hibernate.boot.model.source.internal.hbm.ModelBinder bindProperty 26 WARN: HHH90000003: Use of DOM4J entity-mode is considered deprecated 27 六月 11, 2018 5:36:39 下午 org.hibernate.boot.model.source.internal.hbm.ModelBinder bindProperty 28 WARN: HHH90000003: Use of DOM4J entity-mode is considered deprecated 29 六月 11, 2018 5:36:39 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute 30 INFO: HHH000228: Running hbm2ddl schema update 31 Hibernate: 32 select 33 user0_.ID as ID1_0_0_, 34 user0_.NAME as NAME2_0_0_, 35 user0_.ADDRESS as ADDRESS3_0_0_ 36 from 37 USER user0_ 38 where 39 user0_.ID=? 40 User [id=2, name=YinRui, address=JangSu-NanJing] 41 Hibernate: 42 select 43 user0_.ID as ID1_0_0_, 44 user0_.NAME as NAME2_0_0_, 45 user0_.ADDRESS as ADDRESS3_0_0_ 46 from 47 USER user0_ 48 where 49 user0_.ID=? 50 User [id=2, name=YinRui, address=JangSu-ChangZhou] 51 六月 11, 2018 5:36:39 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop 52 INFO: HHH000030: Cleaning up connection pool [jdbc:mysql://localhost:3306/ssh?serverTimezone=GMT&useSSL=false]
数据库没有改变!
1 package easyStart.Run; 2 3 import org.hibernate.Session; 4 import org.hibernate.SessionFactory; 5 import org.hibernate.boot.MetadataSources; 6 import org.hibernate.boot.registry.StandardServiceRegistry; 7 import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 8 9 import easyStart.Entity.User; 10 11 public class QuickStart { 12 13 public static void main(String[] args) { 14 15 final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build(); 16 SessionFactory sessionFactory = null; 17 try { 18 sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); 19 } catch (Exception e) { 20 StandardServiceRegistryBuilder.destroy(registry); 21 } 22 23 Session session = sessionFactory.openSession(); 24 session.beginTransaction(); 25 // 处理事务 Begin 26 User user1 = session.get(User.class, 2); 27 System.out.println(user1); 28 29 User user2 = session.get(User.class, 2); 30 System.out.println(user2); 31 // 处理事务 End 32 session.getTransaction().commit(); 33 session.close(); 34 sessionFactory.close(); 35 } 36 37 }
1 六月 11, 2018 5:44:50 下午 org.hibernate.Version logVersion 2 INFO: HHH000412: Hibernate Core {5.0.1.Final} 3 六月 11, 2018 5:44:50 下午 org.hibernate.cfg.Environment <clinit> 4 INFO: HHH000206: hibernate.properties not found 5 六月 11, 2018 5:44:50 下午 org.hibernate.cfg.Environment buildBytecodeProvider 6 INFO: HHH000021: Bytecode provider name : javassist 7 六月 11, 2018 5:44:50 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit> 8 INFO: HCANN000001: Hibernate Commons Annotations {5.0.0.Final} 9 六月 11, 2018 5:44:50 下午 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity 10 WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead. Support for obsolete DTD/XSD namespaces may be removed at any time. 11 六月 11, 2018 5:44:51 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 12 WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!) 13 六月 11, 2018 5:44:51 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 14 INFO: HHH000401: using driver [com.mysql.cj.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/ssh?serverTimezone=GMT&useSSL=false] 15 六月 11, 2018 5:44:51 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 16 INFO: HHH000046: Connection properties: {user=root, password=****} 17 六月 11, 2018 5:44:51 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 18 INFO: HHH000006: Autocommit mode: false 19 六月 11, 2018 5:44:51 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 20 INFO: HHH000115: Hibernate connection pool size: 20 (min=1) 21 六月 11, 2018 5:44:51 下午 org.hibernate.dialect.Dialect <init> 22 INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect 23 六月 11, 2018 5:44:51 下午 org.hibernate.boot.model.source.internal.hbm.ModelBinder bindProperty 24 WARN: HHH90000003: Use of DOM4J entity-mode is considered deprecated 25 六月 11, 2018 5:44:51 下午 org.hibernate.boot.model.source.internal.hbm.ModelBinder bindProperty 26 WARN: HHH90000003: Use of DOM4J entity-mode is considered deprecated 27 六月 11, 2018 5:44:51 下午 org.hibernate.boot.model.source.internal.hbm.ModelBinder bindProperty 28 WARN: HHH90000003: Use of DOM4J entity-mode is considered deprecated 29 六月 11, 2018 5:44:52 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute 30 INFO: HHH000228: Running hbm2ddl schema update 31 Hibernate: 32 select 33 user0_.ID as ID1_0_0_, 34 user0_.NAME as NAME2_0_0_, 35 user0_.ADDRESS as ADDRESS3_0_0_ 36 from 37 USER user0_ 38 where 39 user0_.ID=? 40 User [id=2, name=YinRui, address=JangSu-ChangZhou] 41 User [id=2, name=YinRui, address=JangSu-ChangZhou] 42 六月 11, 2018 5:44:52 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop 43 INFO: HHH000030: Cleaning up connection pool [jdbc:mysql://localhost:3306/ssh?serverTimezone=GMT&useSSL=false]
当执行clear函数后,缓存被清理了!再看结果:
1 package easyStart.Run; 2 3 import org.hibernate.Session; 4 import org.hibernate.SessionFactory; 5 import org.hibernate.boot.MetadataSources; 6 import org.hibernate.boot.registry.StandardServiceRegistry; 7 import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 8 9 import easyStart.Entity.User; 10 11 public class QuickStart { 12 13 public static void main(String[] args) { 14 15 final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build(); 16 SessionFactory sessionFactory = null; 17 try { 18 sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); 19 } catch (Exception e) { 20 StandardServiceRegistryBuilder.destroy(registry); 21 } 22 23 Session session = sessionFactory.openSession(); 24 session.beginTransaction(); 25 // 处理事务 Begin 26 User user1 = session.get(User.class, 2); 27 System.out.println(user1); 28 session.clear();// 清理缓存 29 User user2 = session.get(User.class, 2); 30 System.out.println(user2); 31 // 处理事务 End 32 session.getTransaction().commit(); 33 session.close(); 34 sessionFactory.close(); 35 } 36 37 }
1 六月 11, 2018 5:47:09 下午 org.hibernate.Version logVersion 2 INFO: HHH000412: Hibernate Core {5.0.1.Final} 3 六月 11, 2018 5:47:09 下午 org.hibernate.cfg.Environment <clinit> 4 INFO: HHH000206: hibernate.properties not found 5 六月 11, 2018 5:47:09 下午 org.hibernate.cfg.Environment buildBytecodeProvider 6 INFO: HHH000021: Bytecode provider name : javassist 7 六月 11, 2018 5:47:09 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit> 8 INFO: HCANN000001: Hibernate Commons Annotations {5.0.0.Final} 9 六月 11, 2018 5:47:09 下午 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity 10 WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead. Support for obsolete DTD/XSD namespaces may be removed at any time. 11 六月 11, 2018 5:47:10 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 12 WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!) 13 六月 11, 2018 5:47:10 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 14 INFO: HHH000401: using driver [com.mysql.cj.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/ssh?serverTimezone=GMT&useSSL=false] 15 六月 11, 2018 5:47:10 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 16 INFO: HHH000046: Connection properties: {user=root, password=****} 17 六月 11, 2018 5:47:10 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 18 INFO: HHH000006: Autocommit mode: false 19 六月 11, 2018 5:47:10 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 20 INFO: HHH000115: Hibernate connection pool size: 20 (min=1) 21 六月 11, 2018 5:47:10 下午 org.hibernate.dialect.Dialect <init> 22 INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect 23 六月 11, 2018 5:47:10 下午 org.hibernate.boot.model.source.internal.hbm.ModelBinder bindProperty 24 WARN: HHH90000003: Use of DOM4J entity-mode is considered deprecated 25 六月 11, 2018 5:47:10 下午 org.hibernate.boot.model.source.internal.hbm.ModelBinder bindProperty 26 WARN: HHH90000003: Use of DOM4J entity-mode is considered deprecated 27 六月 11, 2018 5:47:10 下午 org.hibernate.boot.model.source.internal.hbm.ModelBinder bindProperty 28 WARN: HHH90000003: Use of DOM4J entity-mode is considered deprecated 29 六月 11, 2018 5:47:11 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute 30 INFO: HHH000228: Running hbm2ddl schema update 31 Hibernate: 32 select 33 user0_.ID as ID1_0_0_, 34 user0_.NAME as NAME2_0_0_, 35 user0_.ADDRESS as ADDRESS3_0_0_ 36 from 37 USER user0_ 38 where 39 user0_.ID=? 40 User [id=2, name=YinRui, address=JangSu-ChangZhou] 41 Hibernate: 42 select 43 user0_.ID as ID1_0_0_, 44 user0_.NAME as NAME2_0_0_, 45 user0_.ADDRESS as ADDRESS3_0_0_ 46 from 47 USER user0_ 48 where 49 user0_.ID=? 50 User [id=2, name=YinRui, address=JangSu-ChangZhou] 51 六月 11, 2018 5:47:11 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop 52 INFO: HHH000030: Cleaning up connection pool [jdbc:mysql://localhost:3306/ssh?serverTimezone=GMT&useSSL=false]
证实了一点:session.clear();// 清理缓存 可以清空缓存内容!