NetBeans HQL 编辑器错误地将 SQL 转换为 SQL
我正在尝试从 Java Web 服务访问 MySQL 数据库。我正在使用 NetBeans IDE 并遵循教程在Web 应用程序
现在,当我尝试测试 HQL 查询:从我得到的调用中:
org.hibernate.exception.SQLGrammarException: could not execute query
blablabla
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'from limit 100' at line 1
bla, bla, bla
翻译后的 SQL 也是错误的:
select from
我使用 Hibernate 逆向工程创建了 Calls.java 类。
这是 Hibernate.cfg.xml
文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.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/datacheck</property>
<property name="hibernate.connection.username">admin</property>
<property name="hibernate.connection.password">####</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
</session-factory>
</hibernate-configuration>
我似乎找不到错误,我搜索了整个互联网:p
类似的线程是 HQL 编辑器未在查询中附加表名称。
I'm trying to access a MySQL database from a Java webservice. I'm using the NetBeans IDE and am following the tutorial Using Hibernate in a Web Application
Now when I try to test the HQL query: from calls I get:
org.hibernate.exception.SQLGrammarException: could not execute query
blablabla
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'from limit 100' at line 1
bla, bla, bla
And the translated SQL is also wrong:
select from
I created the calls.java class using Hibernate Reverse Engineering.
This is the Hibernate.cfg.xml
file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.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/datacheck</property>
<property name="hibernate.connection.username">admin</property>
<property name="hibernate.connection.password">####</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
</session-factory>
</hibernate-configuration>
I can't seem to find the error, and I searched the whole Internet :p
A similar thread is HQL Editor not appending table name in query.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我输入了 HQL 查询,
而它应该是:
首字母大写。
愚蠢的错误,我以为这是数据库表,但显然它是您必须的 POJO 名称指定。
I typed the HQL query
while it should be:
with a capital first letter.
Dumb mistake, I thought it was the database table, but apparently it's the POJO name that you have to specify.