How to close connection like Jparepository and Spring Boot

Asked

Viewed 217 times

1

Hello,

I am working on a project using Spring Boot and am using Jparepository.

I need to close the connection after running a bank operation, for example: query - findAll().

I know it may seem strange, because Jparepository manages all of this automatically, but the project I’m working on needs to do something like this.

Does anyone know how to close a connection manually using Jparepository?

Thank you.

  • The first question is: why does the project need to do this manually? I think the requirement is totally wrong, the responsibility of closing the connection depends on the connection pool, and closing the connection manually is totally not recommended. What’s the problem with that?

  • The reason is that I’m in a project that is using Multi Tenant and one of the Apis is not looking to change Tenant. In other Apis, JPA frees the connections to be able to change Tentant, but in this API this is not happening. That’s why I wanted to try to manually force the change of Tenant. NOTE: the Apis that work have JWT authentication, the one that is not changing the Tenant does not have JWT authentication.

  • I understand, and as a requirement you need only use JpaRepository or can make the necessary implementations?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.