Skip to content

HibernateTemplate.bulkUpdate deprecated but no replacement provided #22271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
djechelon opened this issue Jan 16, 2019 · 1 comment
Closed

HibernateTemplate.bulkUpdate deprecated but no replacement provided #22271

djechelon opened this issue Jan 16, 2019 · 1 comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: invalid An issue that we don't feel is valid

Comments

@djechelon
Copy link
Contributor

I have noticed that during upgrade from Spring 4.3 to 5.1 HibernateTemplate.bulkUpdate has been deprecated

Source: https://docs.spring.io/spring-framework/docs/current/javadoc-api/deprecated-list.html
Source: https://github.com/spring-projects/spring-framework/blob/master/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTemplate.java#L1058

In the docs, it is not specified how to properly replace the handy bulkUpdate method.

Request here is to document how should one replace the deprecated bulkUpdate method in his/her code.


Comment:

I also have read #20972 but fail to understand why can lambdas be more elegant than a handy dirty method.

In my case, I am writing unit tests and I want a quick and not-too-dirty-but-dirty-is-acceptable way to clear the database or do bulk operations.

In the past, I used

new HibernateTemplate(sessionFactory).bulkUpdate("delete from Entity");

Now I have to use
new HibernateTemplate(sessionFactory).execute(session->session.createQuery("delete from Entity").executeUpdate());

In my personal opinion, the second doesn't look so better than the first. And yes, bulkUpdate runs a lambda internally.

@bclozel bclozel added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 17, 2019
@rstoyanchev
Copy link
Contributor

In the docs, it is not specified how to properly replace the handy bulkUpdate method.

It is specified:

* <p><b>A deprecation note:</b> While {@link HibernateTemplate} and this operations
* interface are being kept around for backwards compatibility in terms of the data
* access implementation style in Spring applications, we strongly recommend the use
* of native {@link org.hibernate.Session} access code for non-trivial interactions.
* This in particular affects parameterized queries where - on Java 8+ - a custom
* {@link HibernateCallback} lambda code block with {@code createQuery} and several
* {@code setParameter} calls on the {@link org.hibernate.query.Query} interface
* is an elegant solution, to be executed via the general {@link #execute} method.
* All such operations which benefit from a lambda variant have been marked as
* {@code deprecated} on this interface.

and here:

* @deprecated as of 5.0.4, in favor of a custom {@link HibernateCallback}
* lambda code block passed to the general {@link #execute} method

The underlying reason is is explained in the ticket you referenced:

In anticipation of Hibernate ORM 5.3 (#20850) and for example its removal of legacy positional parameters, let's revisit HibernateTemplate and possibly deprecate affected operations upfront, allowing either for removal in Spring Framework 5.1/5.2 or at least for only supporting them against Hibernate ORM 5.0-5.2 but not 5.3.

@rstoyanchev rstoyanchev added status: invalid An issue that we don't feel is valid in: data Issues in data modules (jdbc, orm, oxm, tx) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants