Java 如何使用自定义 NamingStrategy 在 Eclipse 中配置 Hibernate Tools HQL 编辑器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/659178/
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-08-11 17:30:21  来源:igfitidea点击:

How to configure Hibernate Tools HQL editor in Eclipse with a custom NamingStrategy

javaeclipseidejboss-toolshibernate-tools

提问by digitaljoel

I've installed Hibernate Tools 3.2.4.GA in Eclipse Ganymede. The main driver for installing it was to be able to issue HQL queries interactively.

我已经在 Eclipse Ganymede 中安装了 Hibernate Tools 3.2.4.GA。安装它的主要驱动力是能够以交互方式发出 HQL 查询。

I have configured all of our mapping files, hibernate.properties, etc. and it shows all of our entities and mappings and is able to read a list of tables from the database. It doesn't appear to use the custom naming strategy I specified in the configuration and therefore I can't query anything. The query in the Dynamic SQL Preview is correct except for table names.

我已经配置了我们所有的映射文件、hibernate.properties 等,它显示了我们所有的实体和映射,并且能够从数据库中读取表列表。它似乎没有使用我在配置中指定的自定义命名策略,因此我无法查询任何内容。除了表名外,Dynamic SQL Preview 中的查询是正确的。

The way I configured the naming strategy was to right click the hibernate configuration and select 'edit configuration' In the 'Options' tab I 'browse' for a Naming strategy. Eclipse is able to find the naming strategy and auto-complete it for me, which would indicate it is in the classpath. I then hit OK and still have problems.

我配置命名策略的方式是右键单击休眠配置并选择“编辑配置”在“选项”选项卡中我“浏览”命名策略。Eclipse 能够找到命名策略并为我自动完成它,这表明它在类路径中。然后我点击OK,仍然有问题。

Am I missing something in the naming strategy configuration for hibernate tools (now jboss tools it would appear) or is it broken?

我是否在休眠工具的命名策略配置中遗漏了一些东西(现在它会出现 jboss 工具)还是它坏了?

Optionally, is there another tool that I could use (in or out of eclipse) to issue HQL statements against my database and be able to see the results?

或者,是否有另一种工具可以使用(在 Eclipse 中或在 Eclipse 之外)针对我的数据库发出 HQL 语句并能够查看结果?

UPDATEThe problem was in the NamingStrategy implementation. It prepends a string to the front of every table, and changes camel case to all lower case with underscores. Unfortunately, in the implementation, the string is injected via spring, and there is no default set. That spring injection wasn't happening in hibernate tools, and because there was no default, the string was empty. It has been changed to have a default ( which matches our current spring configuration ) and it is working now.

更新问题出在 NamingStrategy 实现中。它在每个表的前面添加一个字符串,并将驼峰式大小写更改为所有带下划线的小写。遗憾的是,在实现中,字符串是通过spring注入的,并没有设置默认值。在休眠工具中没有发生弹簧注入,并且由于没有默认值,字符串为空。它已更改为具有默认值(与我们当前的 spring 配置相匹配),并且现在正在运行。

回答by Ali Abdel-Aziz

I didn't use Hibernate Tools in Eclipse. But here is an alternative solution to issue HQL statements against your database.

我没有在 Eclipse 中使用 Hibernate Tools。但这里有一个替代解决方案来针对您的数据库发出 HQL 语句。

there is tool called HQEHibernate Query Editor. Hibernate Query Editor (HQE) is a simple application designed to make easy the work of writting HQL/SQL queries for Hibernate. It has simple features like syntax highlight and other editing stuff.

有一个名为HQEHibernate 查询编辑器的工具。Hibernate Query Editor (HQE) 是一个简单的应用程序,旨在简化为 Hibernate 编写 HQL/SQL 查询的工作。它具有简单的功能,如语法高亮和其他编辑内容。

more information about HQEcan be found here https://hqe.dev.java.net/

关于HQE 的更多信息 可以在这里找到https://hqe.dev.java.net/

回答by vsingh

Configure hibernate with myeclipse and you get can various options . This might help http://www.skill-guru.com/blog/tag/hibernate-and-eclipse-tutorial/

使用 myeclipse 配置休眠,您可以获得各种选项。这可能会有所帮助 http://www.skill-guru.com/blog/tag/hibernate-and-eclipse-tutorial/

回答by fastcodejava

You might look into my plugin which can create simple hqls easily. http://fast-code.sourceforge.net/

您可以查看我的插件,它可以轻松创建简单的 hqls。 http://fast-code.sourceforge.net/