2012-09-05 35 views
0

下面的查詢沒有得到執行。它是拋出錯誤。我無法識別錯誤。它由hibenate生成。 驅動程序類org.gjt.mm.mysql.Driver,方言:org.hibernate.dialect.MySQLDialect 請幫助我這是錯誤。MySql從休眠中查詢語法錯誤

的jdbc:mysql的://本地主機:3306/mydb的

select this_.Student_Id as Student1_8_0_, this_.student Name as student2_8_0_, 
     this_.address as address8_0_, this_.Father Name as Father4_8_0_, 
     this_.Mother Name as Mother5_8_0_, this_.Primary Contact No as Primary6_8_0_, 
     this_.Secondary Contact No as Secondary7_8_0_, this_.Occupation as Occupation8_0_, 
     this_.Mode_Id as Mode9_8_0_, this_.Class_Id as Class10_8_0_, 
     this_.Route_No as Route11_8_0_ 
from Tbl_Student this_ 

,如果我跑作爲select * from Tbl_Student這樣它工作正常。

+2

顯示您的代碼和錯誤/異常。 –

+0

如果你直接向Mysql發起這個查詢,會出現什麼錯誤? – Ketan

回答

0

你應該使用反單引號括用空格分隔的列名:

`this_`.`Father Name`, .. 
+0

是的,我得到了錯誤,因爲這個空間在列name.thanks – Jothi

+0

不客氣! :) – Omesh

0

那是什麼碼?它是你的HQL語句還是Hibernate生成的SQL語句?

如果是您的HQL語句:
您必須使用屬性的名稱,即i。即Java成員名稱作爲列名稱。

如果它是由Hibernate生成的SQL語句:
有可能是在映射錯誤,而你使用的空間,而不是在Father_Name,Mother_Name,Primary_Contact_No和Secondary_Contact_No下劃線。