When sharing a Jdbc connection pool between spring-data-jpa and spring-security-oauth's JdbcTokenStore, how to handle transactions? -


we using jdbctokenstore spring-security persist oauth2 access tokens. same application heavily rely on spring-data-jpa. both share connection pool mysql database.

jdbc defaults auto-commit mode , jdbctokenstore appears written assumption auto-commit on. never explicitly commits change.

spring-data , jpa on other hand require transaction write operations. application uses @transactional annotation.

we observing following issue:

  • request (1): client obtains access token. jdbctokenstore inserts database.
  • request (2): then, client uses access token in subsequent request. request rejected since token cannot found in database.

this behaviour explained if transaction request (1) not yet committed.

i'm not familiar internals of spring. possible following happens?

  • some jpa operation acquires jdbc connection #1 pool, sets auto-commit=off, executes number of sql statements, and, then, commits.
  • request (1): jdbctokenstore acquires same jdbc connection #1, executes insert statement. (this happens inside transaction. not committed.)
  • request (2): jdbctokenstore acquires different jdbc connection #2, executes select statement. (this not see uncommitted transaction.)
  • some jpa operation acquires jdbc connection #1 again , commits. (now oauth token committed.)

what configuration avoid this?

while cannot explain root cause, have found fix: switching hikaricp jdbc connection pool (replacing tomcat) eliminated symptoms of describe issue.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -