最近看舊書,李剛那本《輕量級J2EE》在講解hibernate的時候遇到一個問題,就是與mysql鏈接後,明明配置了自動建表,卻總是建不了表,上網查了發現是方言的緣由,到底什麼是方言?這裏要記錄一下。mysql
原來問題是這樣的:sql
<?xml version="1.0" encoding="utf-8"?> <!-- 指定Hiberante3映射文件的DTD信息 --> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://127.0.0.1:3306/hibernate_test</property> <property name="connection.username">root</property> <property name="connection.password">123456</property> <property name="hibernate.c3p0.max_size">20</property> <property name="hibernate.c3p0.min_size">1</property> <property name="hibernate.c3p0.timeout">5000</property> <property name="hibernate.c3p0.max_statements">100</property> <property name="hibernate.c3p0.idle_test_period">3000</property> <property name="hibernate.c3p0.acquire_increment">2</property> <property name="hibernate.c3p0.validate">true</property> <!-- 指定數據庫方言 --> <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property> <!-- 根據須要自動建立數據表 --> <property name="hbm2ddl.auto">update</property> <!-- 顯示Hibernate持久化操做所生成的SQL --> <property name="show_sql">true</property> <!-- 將SQL腳本進行格式化後再輸出 --> <property name="hibernate.format_sql">true</property> <!-- 羅列全部的映射文件 --> <mapping resource="haha/app/domain/News.hbm.xml" /> </session-factory> </hibernate-configuration>
明明已經設置了自動生成表,運行時硬是不生成,報一個「表不存在」的錯,後來查到是方言的問題,就是綠色那行(上面的是正確的)數據庫
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
要好好研究一下,方言究竟是什麼。session
好了,方言就是針對各類流行的數據庫特有的支持,這個問題能夠退散了。。。app
<?xml version="1.0" encoding="utf-8"?>
<!-- 指定Hiberante3映射文件的DTD信息 -->
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://127.0.0.1:3306/hibernate_test</property>
<property name="connection.username">root</property>
<property name="connection.password">123456</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.timeout">5000</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.validate">true</property>
<!-- 指定數據庫方言 -->
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<!-- 根據須要自動建立數據表 -->
<property name="hbm2ddl.auto">update</property>
<!-- 顯示Hibernate持久化操做所生成的SQL -->
<property name="show_sql">true</property>
<!-- 將SQL腳本進行格式化後再輸出 -->
<property name="hibernate.format_sql">true</property>
<!-- 羅列全部的映射文件 -->
<mapping resource="haha/app/domain/News.hbm.xml" />
</session-factory>
</hibernate-configuration>dom