Saga persistence - JPA Issues

Hi,

I’m having trouble getting the JPA store for Sagas to be wired-up correctly in a JPA+Hibernate Spring application.

Setup:
Axon version:

Snippet:

@StartSaga
@SagaEventHandler(associationProperty = “key”)
@Transactional
public void handleEvent(CreatedEvent, @Timestamp DateTime time) {
this.handleAddEvent(event, time);
}


@Bean
@Primary
public MergingPersistenceUnitManager mergingPersistenceUnitManager(){
MergingPersistenceUnitManager mergingPersistenceUnitManager = new MergingPersistenceUnitManager();
mergingPersistenceUnitManager.setPackagesToScan(“my.custom.packages”,“org.axonframework.saga.repository.jpa”);
mergingPersistenceUnitManager.setDefaultPersistenceUnitName(“defaultPersistenceUnit”);
mergingPersistenceUnitManager.setDefaultDataSource(mydatasource());
return mergingPersistenceUnitManager;
}

org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider org.axonframework.saga.repository.jpa.AssociationValueEntry org.axonframework.saga.repository.jpa.SagaEntry

Cluster Config

Switching off explicit-flush seems to have fixed this issue. Are there any side-effects of this?

<axon:jpa-saga-repository id="sagaJpaRepository" resource-injector="sagaInjector" entity-manager-provider="entityProvider" use-explicit-flush="false"/>


Thanks
Jebu.

Hi,

there is definitely a side effect. Probably, your sagas aren’t being persisted at the moment. Transactions are thread-bound (at least, in this context). Therefore, if you do something asynchronous, you need to configure a transaction manager.

You’ll also need to configure the transactionmanager on the (async)saga manager. Once you do that, turning the explicit flush back on should show no errors.

Cheers,

Allard

Updating the AsyncCluster config to include the transaction manager fixed the issue. Now Saga persistence with JPA works! Thanks!