Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate 5.2.5.Final createSQLQuery() method deprecated

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

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.

I got a warning from Eclipse IDE that says: 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.

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?

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.

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

like image 393
Sandoval0992 Avatar asked Dec 17 '16 14:12

Sandoval0992


People also ask

Is Hql deprecated?

hibernate. Query class has been deprecated in favor of new org.

What is native query in hibernate?

You can use native SQL to express database queries if you want to utilize database-specific features such as query hints or the CONNECT keyword in Oracle. Hibernate 3. x allows you to specify handwritten SQL, including stored procedures, for all create, update, delete, and load operations.


1 Answers

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

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

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.

like image 51
Thomas Fritsch Avatar answered Sep 18 '22 15:09

Thomas Fritsch