来自hibernate的MySql查询语法错误

时间:2021-07-02 23:03:05

the following query is not getting executed. it is throwing error. i am not able to identify the error. its is generated by hibenate. Driver class org.gjt.mm.mysql.Driver, dialect:org.hibernate.dialect.MySQLDialect please help me waht is the error.

以下查询未执行。这是投掷错误。我无法识别错误。它是由hibenate生成的。驱动程序类org.gjt.mm.mysql.Driver,方言:org.hibernate.dialect.MySQLDialect请帮我解决错误。

jdbc:mysql://localhost: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_

if i run as select * from Tbl_Student like this it is working fine.

如果我从Tbl_Student这样运行select *它就可以了。

2 个解决方案

#1


0  

You should use back-ticks to enclose column names separated with spaces:

您应该使用反向标记来包含用空格分隔的列名:

`this_`.`Father Name`, ..

#2


0  

What is that code? Is it your HQL statement or is it the SQL statement generated by Hibernate?

这段代码是什么?它是您的HQL语句还是Hibernate生成的SQL语句?

If it is your HQL statement:
You have to use the names of the properties, i. e. the Java member names as column names.

如果是你的HQL语句:你必须使用属性的名称,i。即Java成员名称作为列名称。

If it is the SQL statement generated by Hibernate:
There is probably an error in your mapping, and you used a space instead of an underscore in Father_Name, Mother_Name, Primary_Contact_No and Secondary_Contact_No.

如果它是由Hibernate生成的SQL语句:映射中可能存在错误,并且您在Father_Name,Mother_Name,Primary_Contact_No和Secondary_Contact_No中使用了空格而不是下划线。

#1


0  

You should use back-ticks to enclose column names separated with spaces:

您应该使用反向标记来包含用空格分隔的列名:

`this_`.`Father Name`, ..

#2


0  

What is that code? Is it your HQL statement or is it the SQL statement generated by Hibernate?

这段代码是什么?它是您的HQL语句还是Hibernate生成的SQL语句?

If it is your HQL statement:
You have to use the names of the properties, i. e. the Java member names as column names.

如果是你的HQL语句:你必须使用属性的名称,i。即Java成员名称作为列名称。

If it is the SQL statement generated by Hibernate:
There is probably an error in your mapping, and you used a space instead of an underscore in Father_Name, Mother_Name, Primary_Contact_No and Secondary_Contact_No.

如果它是由Hibernate生成的SQL语句:映射中可能存在错误,并且您在Father_Name,Mother_Name,Primary_Contact_No和Secondary_Contact_No中使用了空格而不是下划线。