姝ら」鐩槸閫氳繃瑙傜湅灏氬鍫傞┈鑰佸笀鐨勮棰戣嚜宸辫繘琛岀粌涔犳暣鐞嗙殑锛屼负鑷繁澶嶄範浣跨敤銆傚ぇ瀹跺彲浠ョ湅涓€涓嬮噷闈㈢殑閰嶇疆娉ㄩ噴锛屼篃鍙互鍘绘壘椹€佸笀鐨勮棰戣嚜宸卞幓瑙傜湅缁冧範銆?/p>
聽
鍏朵腑缂撳瓨銆佷簨鍔°€侀攣鏈」鐩腑鏈秹鍙婏紝瀹為檯搴旂敤涓篃涓嶅ぇ銆傞潰璇曠殑鏃跺€欓渶瑕佺煡閬撱€傞兘鏄煡璇嗙偣锛岀悊瑙e嵆鍙€?/p>
聽
hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
聽 聽 聽 聽 "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
聽 聽 聽 聽 "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
聽
<hibernate-configuration>
聽
聽 聽 <session-factory>
聽
聽 聽 聽 聽 <!-- Database connection settings -->
聽 聽 聽 聽 <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
聽 聽 聽 聽 <property name="connection.url">jdbc:mysql://localhost/hibernate</property>
聽 聽 聽 聽 <property name="connection.username">root</property>
聽 聽 聽 聽 <property name="connection.password">瀵嗙爜</property>
聽
聽 聽 聽 聽 <!-- JDBC connection pool (use the built-in)聽
聽 聽 聽 聽 <property name="connection.pool_size">1</property>-->
聽 聽 聽 聽聽
聽 聽 聽 聽 聽<!-- Enable Hibernate's automatic session context management -->
聽 聽 聽 聽 聽<!-- 鏈€甯哥敤鐨勫氨鏄痶hread锛屼粠褰撳墠绾跨▼閲屾壘鏈夋病鏈塻ession瀵硅薄锛屾湁灏辩敤锛屾病鏈夊氨鍒涘缓鏂扮殑 銆倀hread閰嶇疆鏄敱connection绠$悊浜嬪姟,閫傜敤鍗曚竴鏁版嵁搴?->
聽 聽 聽 聽 聽<!-- jpa 閫傚悎鍒嗗竷寮忔暟鎹簱锛孴ransactionManager鐢眞eb鏈嶅姟鍣ㄦ潵鎻愪緵銆傦紝Tomcat涓嶆彁渚涙閰嶇疆锛堝彲浠ュ€熷姪绗笁鏂圭被搴撳疄鐜帮級锛孞boss鍙互锛屾敞鎰忔湁涓┍鍔ㄧ殑闂锛岃窡鍗曚竴鏁版嵁搴撶殑椹卞姩涓嶄竴鏍?->
聽 聽 聽 聽 聽<!-- 浣跨敤getCurrentSession()寰楀埌session鐨勮瘽锛屽氨寰楄缃緱鍒皊ession鐨勪笂涓嬫枃 -->
聽 聽 聽 聽 <property name="current_session_context_class">thread</property>
聽
聽 聽 聽 聽 <!-- SQL dialect -->
聽 聽 聽 聽 <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
聽
聽 聽 聽 聽 <!-- Enable Hibernate's automatic session context management聽
聽 聽 聽 聽 <property name="current_session_context_class">thread</property>-->
聽
聽 聽 聽 聽 <!-- Disable the second-level cache 聽娉ㄩ噴鎺変笉浣跨敤浜岀骇缂撳瓨
聽 聽 聽 聽 <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
-->
<!-- 鍚敤浜岀骇缂撳瓨 ehcahche锛屽鏁堢巼瑕佹眰楂橈紝蹇呴』瑕佷娇鐢ㄧ殑鏃跺€欏啀浣跨敤锛屽惁鍒欎笉瑕佺敤聽
鎶婄粡甯稿憲璁块棶鐨勶紝鏁版嵁閲忓苟涓嶅ぇ锛屾敼鍔ㄩ潪甯稿皯鐨勭被鏀惧湪缂撳瓨閲岋紝濡傜敤鎴风殑鏉冮檺锛岀粍缁囨満鏋勫彲浠ユ斁鍦ㄧ紦瀛橀噷
-->
<property name="cache.use_second_level_cache">true</property>
<property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="cache.use_query_cache">true</property><!-- 璁剧疆鏌ヨ缂撳瓨 -->
聽
聽 聽 聽 聽 <!-- Echo all executed SQL to stdout 鎵撳嵃SQL璇彞-->
聽 聽 聽 聽 <property name="show_sql">true</property>
聽 聽 聽 聽聽
聽 聽 聽 聽 <!-- 鏍煎紡鍖朣QL璇彞-->
聽 聽 聽 聽 <property name="format_sql">true</property>
聽
聽 聽 聽 聽 <!-- Drop and re-create the database schema on startup -->
聽 聽 聽 聽 <property name="hbm2ddl.auto">update</property>
聽
聽 聽 聽 聽 <mapping resource="com/sun/hibernate/Student.hbm.xml"/>
<mapping class="com.bjsxt.hibernate.Teacher"/>
聽 聽 </session-factory>
聽
</hibernate-configuration>
聽杩橀渶瑕乪hcahche鐨刯ar鍖?/p>