Reputation: 2300
I am upgrading an spring boot app (spring-boot-starter-parent) from 2.6.1 to 3.4.1. part of that upgrade is related to the upgrade of hibernate 5 to 6 and specifically hibernate core 6.6.4.Final with postgresql. In hibernate 5 we have such construct which worked perfectly i.e.
String hql_query = "DELETE from Node as o WHERE o.id IN (:ids)";
Query<?> query = session.createQuery(hql_query);
query.setParameterList("ids", nodeIdList, byte[].class);
in the the above example the class of the returned type Query is not really defined i.e. <?> in Hibernate 6 createQuery is deprecated andit is proposed to move to using a new methods i.e.
createSelectionQuery
or
createQuery(String, Class)
What I do not understand is what should be the class type on a delete statement of the HQL Query class i.e. Query.
I tried the following
Query<Node> query = session.createQuery(hql_query, Node.class);
does not work. An example will be really appreciated
Upvotes: 0
Views: 67
Reputation: 294
I think in the case of a delete, you should use createMutationQuery now. With this method, you don't need to pass Class.
Some documentation here
Upvotes: 1