首页 / JAVA / java – 基本HQL语句总是失败
java – 基本HQL语句总是失败
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 基本HQL语句总是失败,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2318字,纯文字阅读大概需要4分钟。
内容图文
我最近开始尝试使用Hibernate,但我在Netbeans中这样做.这让我不得不使用this example project尝试让我启动并运行.
不幸的是,在“枚举电影标题和使用HQL查询检索演员”这一步骤中,我的HQL查询不会给出结果而是失败,但例外情况如下:
org.hibernate.exception.SQLGrammarException: could not execute query
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
似乎HQL没有生成正确的MySQL语句,但我似乎无法理解为什么,因为到目前为止我已经按照示例的方式进行了操作.
我正在尝试连接到名为’sakila’的本地MySQL数据库,其中包含以下详细信息:
jdbc:mysql://localhost:3306/sakila
这似乎工作正常,因为我能够从Netbeans内部浏览表没问题.
我的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.MySQLInnoDBDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sakila</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.show_sql">true</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<mapping resource="dvdrental/Language.hbm.xml"/>
<mapping resource="dvdrental/FilmActor.hbm.xml"/>
<mapping resource="dvdrental/FilmCategory.hbm.xml"/>
<mapping resource="dvdrental/Category.hbm.xml"/>
<mapping resource="dvdrental/Film.hbm.xml"/>
<mapping resource="dvdrental/Actor.hbm.xml"/>
</session-factory>
</hibernate-configuration>
当我使用HQL查询窗口时,它似乎生成的SQL只会说’选择’这显然是错误的,但我不明白为什么会造成这种情况?
编辑1:HQL查询选项卡显示我的输入
解决方法:
完全愚蠢的理由 – 我甚至没有想过我没有构建项目的事实,所以示例底部的示例代码正确运行(因为它是预编译的).现在没问题.
内容总结
以上是互联网集市为您收集整理的java – 基本HQL语句总是失败全部内容,希望文章能够帮你解决java – 基本HQL语句总是失败所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。