This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Comment

You have to register the synchronization with the transaction somehow. You normally would call TransactionSynchronizationManager.registerSynchron ization, once the transaction has started (so if you put it in a POJO, you can then only test it with a transactional test). Is that what is needed here, or did I miss something?

Comment

All we need is to invoke beforeCompletion() in our service bean (which is comparable to stateless session bean in ejb). The goal here is to set authenticated user's id in jdbc connection -conn.setEndToEndMetrics(userid) for auditing.

In ejb to achieve the behavior all i needed to do was to implement SessionSynchronization interface, and ejb container began calling beforeCompletion() and other jta callbacks.

We are looking to implement the same in Spring.

Comment

I was able to get it to work using TransactionSynchronizationManager.registerSynchron ization.

I was wondering if the same could be achieved via configuration. The reason I am asking is that when classes are wired to each other TransactionSynchronizationManager.isSynchronizatio nActive() may be false and registration of a new synchronization may fail. I noticed that registration is possible only when

TransactionSynchronizationManager.isSynchronizatio nActive() is true.

Any suggestions would be wellcome.

Thanks

Comment

You could write a piece of advice that you apply after the transaction (assuming you are using declarative TX management) that would register a synchronization, then it could be configured with the correct dependency. It's not something that exists in the framework as far as I know because TransactionSynchronizationManager is mainly intended for internal use, but it sounds pretty useful.