-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Transaction synchronization hook - beforeCreatePhase [SPR-13724] #18297
Comments
Lukas Eder commented I confirm that this would be a nice addition to the existing transaction lifecycle listener SPI. In TransactionPhase, we have commit/rollback related hooks, but not "begin" related ones. In addition to the interesting use-case mentioned in this ticket, I have another one from a previous customer where they look up Java EE UserTransactions via JNDI and after doing so, they implemented some logic initialising the Oracle Connection's PL/SQL context with global variables for the session (user ID, contract number, accounts, etc.). This context was part of the application design and was used throughout their stored procedures and views as an additional security layer directly in the database. The ideal place to do this is when a transaction starts. Because they didn't use DI, it was easy for them to implement this "manually" because they created the transaction themselves. With DI (e.g. Spring Transactional), users rely on the DI SPIs made available by Spring, and this particular mechanism is currently missing:
For further reference, there had been a support request just recently on the jOOQ mailing list that was asking about this very feature, with another use-case: Auditing |
The reason why For initialization purposes, we'd have to introduce specific callbacks that the transaction manager invokes on begin and on completion, or as suggested above, decorate transactional processing with an aspect. This could also be implemented in a In any case, this is not part of the scope of transaction synchronizations, so I'll close this issue from that perspective. |
David J. M. Karlsen opened SPR-13724 and commented
Looking at
http://docs.spring.io/autorepo/docs/spring/3.2.5.RELEASE/javadoc-api/org/springframework/transaction/support/TransactionSynchronization.html
and https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/transaction/event/TransactionalEventListener.html / https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/transaction/event/TransactionPhase.html
it would be nice to have a new phase BEFORE_CREATE - emitted by the framework just before it calls the underlying resource to create a new transaction.
The reason for this is that we need to initialize https://www-01.ibm.com/support/knowledgecenter/SSTVLU_8.6.0/com.ibm.websphere.extremescale.javadoc.doc/topics/com/ibm/websphere/objectgrid/spring/SpringLocalTxManager.html
with an ObjectGrid instance (kept threadlocal inside that implementation) just before it will be called by spring to get one.
We do this today by composing a custom annotation (annotated again with
@Transactional
) and intercepting execution with an aspect - but it would be nice to put it directly into framework classes - and I guess it could be interesting for other usecases as well.Issue Links:
1 votes, 3 watchers
The text was updated successfully, but these errors were encountered: