this is quite common of you have a multi-node setup, where commands are divided between the nodes randomly (or at least inconsistently). I have also seen this error pop up in cases where only a single node runs the application. It had to do with the database’s transaction isolation settings. Setting it to read-committed (or read-uncomitted, if you prefer) resolved that issue.
Axon uses locking. Imagine Thread 1 and Thread 2 sending a command that routes to the same aggregate instance. The command bus starts a transaction for both (usually this means a connection is also acquired). Thread 1 loads the aggregate, while Thread 2 blocks at the lock. Thread 1 finishes processing and publishes the results. Thread 2 is released and loads the aggregate. Because the transaction was started before Thread 1 committed, it is possible that the database doesn’t show Thread 1’s results because of the isolation level.
If you use Spring, I also recommend using the LazyConnectionDataSourceProxy, as it will postpone getting the actual connection until it’s really used.