2012-08-04 70 views
4

我得到這個錯誤時,我想在休眠不成功:創建使用表冬眠

SEVERE: Unsuccessful: create table gmail.messages.test (CODE_PERS varchar(255) not null, LAST_NAME varchar(255), FIRST_NAME varchar(255), primary key (CODE_PERS)) 
3.8.2012 18:30: org.hibernate.tool.hbm2ddl.SchemaExport create 
SEVERE: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.test (CODE_PERS varchar(255) not null, LAST_NAME varchar(255), FIRST_NAME varch' at line 1 
3.8.2012 18:30: org.hibernate.tool.hbm2ddl.SchemaExport execute 

這裏創建一個新表是我hibernate.cfg文件

<property name="dialect">org.hibernate.dialect.MySQLDialect</property> 
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/gmail.messages</property> 
<property name="hibernate.connection.username">root</property> 
<property name="hibernate.connection.password">admin</property> 
<!-- <property name="hbm2ddl.auto" value="auto"/> --> 

<property name="hibernate.show_sql">true</property> 
<property name="transaction.factory_class"> 
    org.hibernate.transaction.JTATransactionFactory 
</property> 
<property name="use_outer_join">false</property> 
<property name="jta.UserTransaction">java:comp/UserTransaction</property> 
<property name="hibernate.connection.pool_size">12</property> 
<property name="hibernate.hbm2ddl.auto">create</property> 
<property name="hibernate.default_schema">gmail.messages</property> 
<property name="current_session_context_class">thread</property> 

<mapping resource="HibernateMapping/hibernate.hbm.xml"/> 
+1

我們是否允許在表名中使用。(點)符號? – kosa 2012-08-04 00:11:03

+0

我嘗試使用org.hibernate.dialect.MySQL5Dialect和hibernate.hbm2ddl.auto =「auto」/ update,但仍然是相同的錯誤 – 2012-08-04 00:11:42

+1

我建議你試試簡單的表名,就像message_test,而不是gmail.mes ... .. – kosa 2012-08-04 00:14:19

回答

6

如通過堆棧跟蹤,Hibernate從MySQL數據庫中捕獲了一個異常,因此請嘗試直接在數據庫中執行查詢(比通過框架調試直接要容易得多)。

如果將表名中的點更改爲下劃線,則您的查詢將成功執行。

+0

我創建了具有相同屬性的世界之間沒有點的新數據庫,它的工作原理。謝謝 – 2012-08-04 17:59:29