Sandoval0992
Sandoval0992

Reputation: 1367

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.

Upvotes: 16

Views: 27291

Answers (1)

Thomas Fritsch
Thomas Fritsch

Reputation: 10127

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.

Upvotes: 31

Related Questions