Ahead of Spring's own connection synchronization, which releases the connection at DataSourceUtils.CONNECTION_SYNCHRONIZATION_ORDER. Ending the session runs statements on that connection, so it has to come first.