I have been optimizing the algorithm, and I noticed that Hibernate creates and releases update statements again, rather than reusing them. All of them from one request.
15:57:31,589 TRACE [.JdbcCoordinatorImpl]:371 - Registering statement [sql : 'update ... 15:57:31,591 TRACE [.JdbcCoordinatorImpl]:412 - Releasing statement [sql : 'update ... 15:57:31,592 TRACE [.JdbcCoordinatorImpl]:525 - Closing prepared statement [sql : 'update ... 15:57:31,592 TRACE [.JdbcCoordinatorImpl]:278 - Starting after statement execution processing [ON_CLOSE] 15:57:31,594 TRACE [.JdbcCoordinatorImpl]:371 - Registering statement [sql : 'update ... 15:57:31,595 TRACE [.JdbcCoordinatorImpl]:412 - Releasing statement [sql : 'update ... 15:57:31,596 TRACE [.JdbcCoordinatorImpl]:525 - Closing prepared statement [sql : 'update ... 15:57:31,596 TRACE [.JdbcCoordinatorImpl]:278 - Starting after statement execution processing [ON_CLOSE] 15:57:31,597 TRACE [.JdbcCoordinatorImpl]:371 - Registering statement [sql : 'update ... 15:57:31,599 TRACE [.JdbcCoordinatorImpl]:412 - Releasing statement [sql : 'update ... 15:57:31,600 TRACE [.JdbcCoordinatorImpl]:525 - Closing prepared statement [sql : 'update ... 15:57:31,601 TRACE [.JdbcCoordinatorImpl]:278 - Starting after statement execution processing [ON_CLOSE]
The main method of the algorithm has the annotation @Scope and a @Transactional . The expected behavior is that if something goes wrong, the ROLLBACK algorithm updates.
The algorithm below uses @Service , which has a different @Scope and also @Transactional . A service is one that uses Hibernate to update the database using session.update(entity) . The documentation says that by default, nested transactions reuse the transaction if it exists.
- Is this statement correct?
- Can changing a region create problems?
- How can I use Hibernate to reuse a statement during a transaction?
Thank you for attention
source share