Hardcoded DomainEventEntry table

We have several projects using Axon that share a DB schema. We want to avoid that different projects all write their events in the same event table unfortunately these tables are hardcoded in the DefaultEventEntryStore. We fixed the problem by creating different tables that we refer to with an alias defined per DB user. That way we have different physical tables but they appear as DomainEventEntry to the application.
Since I don’t think this approach is ideal and may not work for everyone I made a few small changes to the DefaultEventEntryStore that allow you to define your own eventEntry classes (and tables). This example uses reflections to create new instances but this could easily be replaced by actual constructors/factories for performance reasons.
I don’t like making changes to framework code because it adds the overhead of maintaining these changes whenever the framework changes so for us the alias solution is best but I included this solution as it may help others.

To use it I made a few changes in the spring config:

service.bits.kernel.infra.persistence org.axonframework.saga.repository.jpa ...

CustomEventEntryStore.java (18 KB)

Create an orm.xml file in your src/main/resources/META-INF directory with the following:

<?xml version="1.0" encoding="UTF-8"?>

Replace the table names with your naming convention.


I did not know you could combine xml with annotation driven entities, thank you very much.

I added the following line the entityManagerFactory bean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) in the spring xml config to make sure it picked up the file:

No problem!

You shouldn’t need to list it in your Spring configuration as it is a JPA standard configuration file. Your JPA provider would look for this file on its own.