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.
hibernate. Query class has been deprecated in favor of new org.
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.
The javadoc of the deprecated QueryProducer.createSQL(String)
describes what to use instead:
Deprecated. (since 5.2) use
createNativeQuery(String)
instead
Create aNativeQuery
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With