Transactional Scopes
By default, calling the API of Data Hub happens within a transactional context. However, there are some exceptions where the API methods do not allow transactions to be present. The restriction is done to avoid inconsistent states and boost performance.
Exceptions to the transactional context rule include the following. If these methods are called in a transaction, unforeseen behavior might occur or a RuntimeException is thrown.
- com.hybris.datahub.core.adapter.api.CoreAdapterFacade#completePublication
- com.hybris.datahub.facade.event.DataHubPoolActionFacade#createPublicationAction
- com.hybris.datahub.facade.event.DataHubPoolActionFacade#createCompositionAction
- com.hybris.datahub.facade.item.DataItemFacade#deleteByFeed(...,...,...)
- com.hybris.datahub.service.composition.DataHubCompositionService#startComposition
- com.hybris.datahub.service.DataHubEventListenerRegistry#notifyListeners
- com.hybris.datahub.service.ItemDeletionService#deleteItems
- com.hybris.datahub.service.PublicationActionService#completeTargetSystemPublication
- com.hybris.datahub.service.publication.DataHubPublicationService#publish
- com.hybris.datahub.adapter.AdapterService#publish
If you are providing additional functionality based on Data Hub, you should know the transactional context for the code being called by Data Hub.
There are three main entry points with different requirements regarding transactions.
Custom Handlers
Custom handlers, such as Grouping or CompositionRuleHandlers, are executed within a transaction per each call to the handler. Therefore, the logic within the handler must be self-contained. Also, it should not have any side effects that cannot be reverted in the case of a rollback of the transaction.
Adapter Services
The publish method of any AdapterService implementation is called outside a transaction. The implementation also should take care of transactions for the AdapterService if necessary.