Failing to load an aggregate on service restart.

We’re attempting to load an aggregate from a repository in a component by it’s id.
Upon attempting to do so we encounter

Invocation of init method failed; nested exception is java.lang.IllegalStateException: No UnitOfWork is currently started for this thread.

We’ve attempted to overcome this by creating a UnitOfWork via

val uow = DefaultUnitOfWork.startAndGet(null)

then performing an execute { … }

This helped resolve the previous problem but resulted in:

Invocation of init method failed; nested exception is org.axonframework.eventsourcing.eventstore.EventStoreException: An event with identifier [6b7b992b-ca8c-4ec0-b7bd-c27c5ab931e7] could not be persisted

We have tried two approaches resulting with the above error.

First approach was to call the aggregate.function() where said function would call apply(Event) // this would trigger the error above.
The second approach was to publish event that would be picked up by an EventHandler that would in tern call the aggregate.function() which would call apply(Event). // this would also trigger the above error.

We’re not clear on how to proceed or why we’re experiencing the problems above.

Never mind resolved :slight_smile:

Hi Michael,

Glad to hear you’ve resolved the issue you’re encountering!
Would you mind sharing here with everybody what you did to correctly load the Aggregate and call one of it’s functions, within the context of a UnitOfWork?

Cheers,
Steven