eclipse Hibernate 5.2.5.Final createSQLQuery() 方法已弃用

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

Hibernate 5.2.5.Final createSQLQuery() method deprecated

javasqleclipsehibernate

提问by Sandoval0992

I'm using the createSQL()method in Hibernate to make an insert operation in my database.

我正在使用createSQL()Hibernate 中的方法在我的数据库中进行插入操作。

What I want to do is declraing a custom SQL statement so that I can apply a MD5()function to a field on a table. That's why I can't just simply use the save(Object)method.

我想要做的是声明一个自定义 SQL 语句,以便我可以将MD5()函数应用于表上的字段。这就是为什么我不能简单地使用该save(Object)方法。

I got a warning from Eclipse IDE that says: The method createSQLQuery(String) from the type QueryProducer is deprecated.

我收到来自 Eclipse IDE 的警告说: The method createSQLQuery(String) from the type QueryProducer is deprecated.

Despite of this the insert operation is performing as expected.

尽管如此,插入操作仍按预期执行。

The current version of Hibernate I'm using on my project is 5.2.5.Final.

我在我的项目中使用的当前 Hibernate 版本是 5.2.5.Final。

So, the question would be: is there another way to achieve the same in this version of Hibernate in order to get rid of that annoying warning?

所以,问题是:有没有另一种方法可以在这个版本的 Hibernate 中实现相同的功能,以摆脱那个烦人的警告?

I also know adding @SuppressWarnings("deprecation")annotation will solve the issue, but I'm not pretty sure whether it will cause any problems in the future.

我也知道添加@SuppressWarnings("deprecation")注释可以解决这个问题,但我不太确定它是否会在将来引起任何问题。

It's worth mentioning that I'm a begginer using this framework.

值得一提的是,我是使用这个框架的初学者。

回答by Thomas Fritsch

The javadoc of the deprecated QueryProducer.createSQL(String)describes what to use instead:

已弃用的 javadocQueryProducer.createSQL(String)描述了要使用的内容:

Deprecated. (since 5.2) use createNativeQuery(String)instead
Create a NativeQueryinstance for the given SQL query string.

已弃用。(自 5.2 起)createNativeQuery(String)改为使用为给定的 SQL 查询字符串
创建一个NativeQuery实例。

Just adding @SuppressWarnings("deprecation")is usually no good idea, because you may get problems in the future; i.e. when you move to a newer Hibernate version where the now deprecated method then will have been removed.

只是添加@SuppressWarnings("deprecation")通常不是什么好主意,因为您将来可能会遇到问题;即当您移动到较新的 Hibernate 版本时,现在已弃用的方法将被删除。