Axon error upon retrieving and reconstructing an existing aggregate state

Hi there,

I am new to axon and am helping to implement an inventory management system. We have a proof of concept setup with event sourced aggregates. Creating new aggregates with an initial state appears to work. When we try to post a ‘correction’ to an exisiting aggregate then things seems to fall apart. I have posted the error below:

17:55:26,683 WARN [org.axonframework.eventsourcing.eventstore.EmbeddedEventStore] (RMI TCP Connection(24)-192.168.56.1) Error reading snapshot. Reconstructing aggregate from entire event stream. Caused by: java.lang.NullPointerException null
17:55:26,689 WARN [org.axonframework.commandhandling.callbacks.LoggingCallback] (RMI TCP Connection(24)-192.168.56.1) Command resulted in exception: com.owfg.sim.pim.axon.prototype2.commandside.inventorydocument.commands.CorrectInventoryDocumentCommand: java.lang.NullPointerException
at org.axonframework.eventsourcing.eventstore.jpa.JpaEventStorageEngine.fetchDomainEvents(JpaEventStorageEngine.java:180)

The error seems to indicate that it checks if there is a snapshot for this existing aggregate root first and then attempts to reconstruct it using its previously committed events. Since we have no snapshots then it would make sense it would go right to the event stream. The events for this aggregate root do exist and I am certain that I am using the correct UUID to obtain a ‘handle’ to it.

Meta Data associated with single event tied to the aggregate root:

traceId2662b8dd-19fc-4772-9ce8-fcdc6400214dcorrelationId2662b8dd-19fc-4772-9ce8-fcdc6400214d

Payload(sanitized):

<…axon.prototype2.commandside.inventorydocument.events.InventoryDocumentPostedEvent>e48f19e0-6fdf-4b04-b4c0-34e01d67dc2bTEST_LOCATIONTEST_TYPE1691168<…poc.inventorydocument.InventoryChange>21499299961714000000INVENTORY_ADDED…
.
. //business specific state information removed
.
</…axon.prototype2.commandside.inventorydocument.events.InventoryDocumentPostedEvent>

I have bolded the aggregate identifier in the payload. Has anyone encountered something like this? Additionally, I can provide more information wrt our axon setup, but I am unsure where to start and do not want to bog down this post with unnecessary detail. If, however, something is requested then I would be more than happy to post it.

Thank you in advance,

Justin.

One other thing: we are using Axon 3.0.4

Upon further investigation, I was able to step through the core axon code and came to the source of the issue:

return **transactionManager**.fetchInTransaction(
        () -> entityManager().createQuery(
                "SELECT new org.axonframework.eventsourcing.eventstore.GenericTrackedDomainEventEntry(" +
                        "e.globalIndex, e.type, e.aggregateIdentifier, e.sequenceNumber, " +
                        "e.eventIdentifier, e.timeStamp, e.payloadType, " +
                        "e.payloadRevision, e.payload, e.metaData) " + "FROM " + domainEventEntryEntityName() + " e " +
                        "WHERE e.aggregateIdentifier = :id " + "AND e.sequenceNumber >= :seq " +
                        "ORDER BY e.sequenceNumber ASC")

It would appear the transactionManager member is not set and a null pointer exception is being thrown.

We have this line of code in our configuration:

.configureEmbeddedEventStore(c -> new JpaEventStorageEngine(pimEntityManagerProvider,null))

That null is where the TransactionManager should go. We should investigate further and include a proper transaction manager first on our end. If there are any further issues Ill reply to this thread.

Thanks

If you’re using Spring, you can use the SpringTransactionManager instance to wrap Spring’s own PlatformTransactionManager.
Otherwise, you’ll have to create an implementation that creates the transactions in the way your current platform expects you to do so.

Kind regards,

Allard

Hi Allard,

We ended up doing just that and it worked. Thanks for that. We are now onto saga persistence and the JpaSagaStore.

cheers,

Justin.