eclipse 如何测试 JPA 查询?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9567142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 17:48:01  来源:igfitidea点击:

How to test JPA queries?

eclipsehibernatejpanetbeans

提问by Valter Silva

I'm developing a website with JSF with JPA. So I configure a DataSource in my Glassfish instance and in my project too.

我正在使用带有 JPA 的 JSF 开发一个网站。所以我在我的 Glassfish 实例和我的项目中配置了一个数据源。

But I wonder, how can I test my JPA queries in Eclipse ?

但我想知道,如何在 Eclipse 中测试我的 JPA 查询?

In Netbeans, for example, you just have to do a right-click on the hibernate.cfgfile and "Run HQL queries"(translating) There's something like this in Eclipse ?

例如,在 Netbeans 中,您只需右键单击hibernate.cfg文件并“运行 HQL 查询”(翻译) Eclipse 中有类似的东西吗?

UPDATE:Following the comments I install the Hibernate Tools then try to use the HQL Editor, but gives me this strange error below :

更新:按照评论,我安装了休眠工具,然后尝试使用 HQL 编辑器,但在下面给了我这个奇怪的错误:

configuration

配置

error

错误

Any idea how can I solve this ?

知道如何解决这个问题吗?

Just to make myself clear, this is my JPA configuration : enter image description here

为了让自己清楚,这是我的 JPA 配置: 在此处输入图片说明

UPDATE 2:I did what @kenChan recommend but it seems that I have one error left: (I didn't know that I have to put the MySQL driver in the classpath, in Hibernate Tools configuration, tkanks KenChan.)

更新 2:我做了@kenChan 推荐的事情,但似乎我还剩下一个错误:(我不知道我必须将 MySQL 驱动程序放在类路径中,在 Hibernate Tools 配置中,tkanks KenChan。)

enter image description hereThe error: enter image description here

在此处输入图片说明错误: 在此处输入图片说明

UPDATE 3:@KenChan I tried to create a property file (I found a similar problem topic here) but still gives the same error:

更新 3:@KenChan 我试图创建一个属性文件(我在这里找到了一个类似的问题主题)但仍然给出相同的错误:

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

UPDATE 4:IT WORKS!

更新 4:它有效!

I was missing one 's' in the end of this line:

我在这一行的末尾遗漏了一个 's':

hibernate.connection.provider_class

In the end my hibernate.properties stay this way:

最后我的 hibernate.properties 保持这样:

hibernate.connection.password=***********
hibernate.connection.username=*******
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.url=jdbc\:mysql\://********\:3306/********
hibernate.connection.provider_class=org.hibernate.connection.DriverManagerConnectionProvider
hibernate.datasource=
hibernate.transaction.manager_lookup_class=
hibernate.cache.use_query_cache=false

Thank you @KenChan by your support.

谢谢@KenChan 的支持。

回答by Ken Chan

Yes . You can install Hibernate Tools, which is an eclipse plugin designed for hibernate 3 .It provides the editor for writing, editing and executing query written in HQL or Criteria API.

是的 。您可以安装Hibernate Tools,这是一个专为 hibernate 3 设计的 eclipse 插件。它提供了用于编写、编辑和执行以 HQL 或 Criteria API 编写的查询的编辑器。

See thisfor more information

请参阅了解更多信息

Regarding to your errors , you should import the MySQL JDBC Driver in the ClassPathtab when editing the hibernate configuration.

关于您的错误,您应该在编辑休眠配置时在ClassPath选项卡中导入 MySQL JDBC 驱动程序。