標籤:對象 網上 hbm rdd post server org where name
最近在學習hibernate,其中關於錯誤的問題真是一頭大,各種各樣的奇葩錯誤層出不窮,簡直是受不了了。 用hibernate操作資料庫,在使用hibernate進行把持久化類自動產生相關資料庫表的時候,出現了一些問題。 其中有上篇錯誤《hibernate學習錯誤--之一》,在上篇錯誤解決完成後,進行測試時通過了,沒有報錯,但是卻沒有產生表,控制台視窗顯示一些找不到相關table的警告,找了半天也不知道錯誤出現再哪兒,查看設定檔感覺也沒問題,設定檔上的一些基本資料,有些是原封不動的從以前一些其他的項目種拷貝過來的。 <property name="connection.url"> jdbc:mysql://localhost:3306/hibernate_1 </property> <property name="hbm2ddl.auto">update</property> <property name="dialect"> org.hibernate.dialect.MySQLInnoDBDialect </property> <property name="show_sql">true</property> <property name="format_sql">true</property>上面是以前的部分設定檔,其中標紅的部分就是不能產生表的原因--方言的配置版本問題。在網上找到一些資料,並附有一些關於方言版本的配置問題。
方言的設定,是跟資料庫的版本有關係的。將上面設定檔的代碼改成一下就沒問題了: <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property> hibernate中的dialect即翻譯過來的“方言”。 因為hibernate是要將Java對象轉換成資料庫來描述的,而關聯式資料庫實際上卻有很多,各個不同的企業、公司、組織等開發了不同的資料庫如Oracle、Mysql、SQL Server等等,這些資料庫為了提高效能或增加提供一些額外的標準和文法,因此hibernate為了更好的適配各種關聯式資料庫,針對每種資料庫都指定了一個方言dialect。 更簡單直觀的理解就是可以將dialect可以看作一個翻譯器,不同的dialect可以將不同版本的資料庫語言翻譯成hibernate能統一理解的語言。 我上面出現的錯誤就是方言的版本和所使用的資料庫版本不適配。 以下是關於各個版本的資料庫對應的方言:
資料庫 |
方言(Dialect) |
DB2 |
org.hibernate.dialect.DB2Dialect |
DB2 AS/400 |
org.hibernate.dialect.DB2400Dialect |
DB2 OS390 |
org.hibernate.dialect.DB2390Dialect |
PostgreSQL |
org.hibernate.dialect.PostgreSQLDialect |
MySQL5 |
org.hibernate.dialect.MySQL5Dialect |
MySQL5 with InnoDB |
org.hibernate.dialect.MySQL5InnoDBDialect |
MySQL with MyISAM |
org.hibernate.dialect.MySQLMyISAMDialect |
Oracle(any version) |
org.hibernate.dialect.OracleDialect |
Oracle 9i |
org.hibernate.dialect.Oracle9iDialect |
Oracle 10g |
org.hibernate.dialect.Oracle10gDialect |
Oracle 11g |
org.hibernate.dialect.Oracle10gDialect |
Sybase |
org.hibernate.dialect.SybaseASE15Dialect |
Sybase Anywhere |
org.hibernate.dialect.SybaseAnywhereDialect |
Microsoft SQL Server 2000 |
org.hibernate.dialect.SQLServerDialect |
Microsoft SQL Server 2005 |
org.hibernate.dialect.SQLServer2005Dialect |
Microsoft SQL Server 2008 |
org.hibernate.dialect.SQLServer2008Dialect |
SAP DB |
org.hibernate.dialect.SAPDBDialect |
Informix |
org.hibernate.dialect.InformixDialect |
HypersonicSQL |
org.hibernate.dialect.HSQLDialect |
H2 Database |
org.hibernate.dialect.H2Dialect |
Ingres |
org.hibernate.dialect.IngresDialect |
Progress |
org.hibernate.dialect.ProgressDialect |
Mckoi SQL |
org.hibernate.dialect.MckoiDialect |
Interbase |
org.hibernate.dialect.InterbaseDialect |
Pointbase |
org.hibernate.dialect.PointbaseDialect |
FrontBase |
org.hibernate.dialect.FrontbaseDialect |
Firebird |
org.hibernate.dialect.FirebirdDialect |
學習hibernate出現錯誤--之二(方言)