Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A substitute for deprecated setParameter(String name, Object val, Type type)

Tags:

java

hibernate

Since Hibernate 5.2 Query<R>.setParameter(String name, Object val, Type type) is deprecated and the javadoc says to use org.hibernate.query.Query instead.

I did this:

org.hibernate.query.Query<String> q = s.createQuery("select f from Foo f where f.bar = :bar", String.class);
q.setParameter("bar", "bar", org.hibernate.type.StringType.INSTANCE);

My Eclipse still complains that .setParameter( is deprecated.

Any ideas on how can I override the type when binding a parameter to a Query?

like image 214
Gustavo Avatar asked Jul 26 '16 19:07

Gustavo


1 Answers

If you see the class javadoc for org.hibernate.Query, you'll notice that the entire interface contract was deprecated and replaced with the new org.hibernate.query.Query contract.

The new query contract in org.hibernate.query.Query also has its equivalent:

Query<R> setParameter(String name, Object value, Type type);

UPDATE

There was an issue logged HHH-10839 that was fixed in the 5.2.1.Final release. That fix added this method back to the org.hibernate.query.Query contract.

like image 148
Naros Avatar answered Oct 23 '22 04:10

Naros