NetBeans HQL 编辑器错误地将 SQL 转换为 SQL

发布于 2024-10-31 02:59:12 字数 2114 浏览 0 评论 0原文

我正在尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨的味道风的声音 2024-11-07 02:59:12

我输入了 HQL 查询,

from call

而它应该是:

from Call

首字母大写。

愚蠢的错误,我以为这是数据库表,但显然它是您必须的 POJO 名称指定。

I typed the HQL query

from call

while it should be:

from Call

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文