Sleep mode 5.2.5. CreateSQLQuery () source method deprecated

I am using the createSQL() method in Hibernate to perform an insert operation on my database.

What I want to do is to describe a custom SQL statement so that I can apply the MD5() function to a field in a table. Therefore, I cannot just use the save(Object) method.

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

Despite this, the insert operation is performed as expected.

The current version of Hibernate that I use in my project is 5.2.5.Final.

So the question will be: is there any other way to achieve the same in this version of Hibernate in order to get rid of this annoying warning?

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

It is worth noting that I am starting to use this framework.

+6
source share
1 answer

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

Outdated. (starting with 5.2) use createNativeQuery(String) instead Create an instance of NativeQuery for a given SQL query string.

Just adding @SuppressWarnings("deprecation") usually not a good idea, because you may have problems in the future; those. when you switch to a newer version of Hibernate, where now the deprecated method has been removed.

+16
source

Source: https://habr.com/ru/post/1013242/


All Articles