EventStore Configuration with Postgres [Axon 4]

The application was previously configured correctly but something changed and I’m slightly struggling in determining the root cause (it’s also getting late so plan to restart tomorrow).


2019-01-24 17:00:59.005 ERROR 15490 — [tTaskScheduler3] o.s.s.s.TaskUtils$LoggingErrorHandler : Unexpected error occurred in scheduled task.

org.axonframework.eventsourcing.eventstore.EventStoreException: An event with identifier [c668cd0e-6f3c-433f-a7f7-da58eed6bd2a] could not be persisted
at org.axonframework.eventsourcing.eventstore.AbstractEventStorageEngine.handlePersistenceException( ~[axon-eventsourcing-4.0.jar:4.0]
at org.axonframework.eventsourcing.eventstore.jpa.JpaEventStorageEngine.appendEvents( ~[axon-eventsourcing-4.0.jar:4.0]
at org.axonframework.eventsourcing.eventstore.AbstractEventStorageEngine.appendEvents( ~[axon-eventsourcing-4.0.jar:4.0]
at org.axonframework.eventsourcing.eventstore.AbstractEventStore.prepareCommit( ~[axon-eventsourcing-4.0.jar:4.0]
at org.axonframework.eventhandling.AbstractEventBus.publish( ~[axon-messaging-4.0.jar:4.0]
at org.axonframework.eventhandling.EventBus.publish( ~[axon-messaging-4.0.jar:4.0]
at com.aramark.ess.command.domain.SyncScheduler$ ~[classes/:na]
at ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at [spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at java.util.concurrent.Executors$ [na:1.8.0_162]
at [na:1.8.0_162]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201( [na:1.8.0_162]
at java.util.concurrent.ScheduledThreadPoolExecutor$ [na:1.8.0_162]
at java.util.concurrent.ThreadPoolExecutor.runWorker( [na:1.8.0_162]
at java.util.concurrent.ThreadPoolExecutor$ [na:1.8.0_162]
at [na:1.8.0_162]
Caused by: javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process ‘persist’ call
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke( ~[spring-orm-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at com.sun.proxy.$Proxy133.persist(Unknown Source) ~[na:na]
at$ForEachOp$OfRef.accept( ~[na:1.8.0_162]
at$3$1.accept( ~[na:1.8.0_162]
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining( ~[na:1.8.0_162]
at ~[na:1.8.0_162]
at ~[na:1.8.0_162]
at$ForEachOp.evaluateSequential( ~[na:1.8.0_162]
at$ForEachOp$OfRef.evaluateSequential( ~[na:1.8.0_162]
at ~[na:1.8.0_162]
at ~[na:1.8.0_162]
at org.axonframework.eventsourcing.eventstore.jpa.JpaEventStorageEngine.appendEvents( ~[axon-eventsourcing-4.0.jar:4.0]
… 14 common frames omitted


The above exception is fired from



As stated in the title we’re using Postgres and I see events applied to aggregates in domain_event_entry.
This event is fired from a standalone component with it’s intended target being a Saga. The associatedId is defined and the event handler in the Saga is decorated with a @StartSaga

Finally here is the AxonConfiguration currently in place:


class AxonFrameworkConfiguration {
    private val log: Logger = LoggerFactory.getLogger(this.javaClass)

    fun registerInterceptors(commandBus: CommandBus) {

    fun snapshotterFactoryBean() = SpringAggregateSnapshotterFactoryBean()

    fun eventSchemaFactory(): EventTableFactory {
        return PostgresEventTableFactory.INSTANCE

    fun eventSchema(): EventSchema {
        return EventSchema()

    fun sagaSqlSchema(): SagaSqlSchema {
        return PostgresSagaSqlSchema()


application yml


  port: 8081
    name: ${SERVICE_NAME}
    url: jdbc:postgresql://${POSTGRES_HOST_DEV}:5432/${SERVICE_NAME}
    username: ${POSTGRES_USER_DEV}
    password: ${POSTGRES_PASSWORD_DEV}
    driver-class-name: org.postgresql.Driver
      ddl-auto: create-drop
    database-platform: org.hibernate.dialect.PostgreSQLDialect
        synchost: 100
        syncmodel: 100
        syncpoint: 100
    default-topic: axon-events
      retries: 5
      transaction-id-prefix: esstx
      group-id: external-sync-group
    client-id: ${random.uuid}
    bootstrap-servers: ${KAFKA_URL}:9092
    enabled: true
    messages: jackson
        mode: tracking
        source: kafkaMessageSource


Thank you in advance for any feedback I could get to help understand where I’ve misconfigured or misunderstood the framework.

I should note that I’ve attempted to perform a publish to the eventbus vs the event store to the same effect and accidentally pasted slightly stale code although the error is the same.

The event is being fired from a scheduled runnable therefore a different thread. I don’t know if this has an impact.

“Caused by: javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread”.

Perhaps just need to ensure the scheduled runnable executes with a transaction? Something along the lines of…

@Scheduled(cron = "0 0 0 * * *", zone="GMT")
public void processXXX() {"Processing...");
    ... Axon code

You may be right but I believe I’m still missing something. Here is the entire class and the respective scheduler.

internal class SyncScheduler(private val eventBus: EventBus,
                             private val taskScheduler: TaskScheduler,
                             private val syncpointRepository: Repository<SyncPoint>) {

    lateinit var syncmodelService: SyncModelService

    fun onLoad() {
        // TODO:

    fun handle(event: SyncPointCreatedEvent) {
        syncpointRepository.load( {
            val syncModel = syncmodelService.findById(it.syncModelId)
            schedule(SyncExecutor(syncPointId =,
                                  syncModelId =,
                                  syncHostId = syncModel.syncHostId),

    private inner class SyncExecutor(private val syncPointId: String,
                                     private val syncModelId: String,
                                     private val syncHostId: String): Runnable {
        override fun run() {
            println("Sync Triggered for $syncPointId")
            val event = SyncPointTriggeredEvent(
            eventBus.publish(asEventMessage<Any>(event)) // CRASH HAPPENS HERE!

    fun schedule(task: Runnable, cronExpression: String) {
        taskScheduler.schedule(task, CronTrigger(cronExpression))

I could imagine that - as you are using a private inner class and @Transactional is AOP based - Spring is not be able to build a dynamic proxy and intercept the call and thus will not be able to open a transaction.

I think Michael L is right on that one. I think your @Transactional annotations are not placed where Spring has any influence.

Also, EventHandling itself is already asynchronous. Consider doing these calls synchronously to simplify things for yourself.