Error on Event handler

Hi,
I get this error when trying to run a command

Command XYZ resulted in org.springframework.transaction.TransactionSystemException(Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction)

Any idea what may be wrong?

Hi Harvey,

Is that a consistent error or only in some scenarios?
I find it hard to figure out what the issue is based on just the exception, but it sounds like appending the event to the event store went wrong.
How is your event store configured? Maybe that can shed some light on your issue.

Cheers,

Steven

Hi Stephen,

This happens only when trying to update a certain aggregate, and consequently the view from the events of the aggregate. Other aggregates don’t have this problem, so that’s what puzzles me.

The event store is automatically created by axon at application start right? I don’t have any explicit configuration for it. The only time I configure an event store is when I autowire it for snapshot configuration which I’ve not yet done.

Hi Harvey,

this error occurs when a transaction cannot be committed, because it has been marked as “rollback only”. Hibernate does this automatically when an operation on the EntityManager (such as a query) fails to execute. This may be the case in your Event Handlers that update the query model, or by Axon when it’s inserting an Event in the EventStore.

Exceptions in Event Handlers are logged by default. If there is an error in command handling, it is reported as a result of the command. Do you use the CommandGateway or the CommandBus to dispatch your commands. Do you use Sagas? If so, which one do they use?

Make sure you log the (Exception) result of commands send. Axon doesn’t log these (since it reports them using the API). Note that the CommandGateway.send() method returns a CompletableFuture. You can use that CompletableFuture to discover if there are any errors processing a command.

Hope this helps.
Cheers,

Allard

Thank you Allard. I use the CommandGateway. I’ve registered a callback and now get the source of the error.