Skip to content
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

Automatically handle transactions in JavaEE environment #36

Open
cerker opened this issue Oct 29, 2019 · 0 comments
Open

Automatically handle transactions in JavaEE environment #36

cerker opened this issue Oct 29, 2019 · 0 comments
Assignees
Milestone

Comments

@cerker
Copy link
Contributor

cerker commented Oct 29, 2019

The hibersap-ejb library implements the HibersapSession annotation and HibersapSessionInterceptor which can be used to automatically inject a Hibersap session into an EJB. With this approach, the application developer is responsible for opening and closing transactions on the session in order to commit/rollback the transactions in SAP.

JavaEE offers a transaction synchronization mechanism where a javax.transaction.Synchronization implementation can be added to the current exception which will be notified when a transaction is completed, i.e. right after the Tx manager committed or rolled back the other resources.

Additionally, the synchronization mechanism gives the possibility to store data in a transaction context, which should be used here to store a Hibersap session for later use in the HibersapSessionInterceptor, when the Hibersap sessions need to be committed or rolled back. Now the sessions are stored in the context data of the InvocationContext. The transaction context is a much better place, since it behaves correctly even with nested transactions.

The Hibersap EJB component shall make use of this by registering a Synchronization object with every transaction where a HibersapSessionInterceptor is used and store the Hibersap sessions in the transaction context. After the container has completed a transaction, the synchronization object shall commit or rollback the Hibersap transaction which effectively will commit or rollback the transaction in SAP.

This is not a watertight transactional approach since it is still possible that a commit in SAP fails while at this point the other resources that take part in the (distributed) transaction are already committed. However, for most use cases this should be sufficient. If real distributed transactions are needed, application developers should consider using a resource adapter for SAP, like the Cuckoo RA.

@cerker cerker self-assigned this Oct 29, 2019
@cerker cerker added this to the future milestone Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant