How to make JPA Event Store use separate database?

I have Axon Framework up and running in a spring boot app. By excluding the axon-server-connector from the spring-boot-starter package, I have it successfully creating the tables and storing events in SQL Server. But I cannot figure out how to put those tables in their own schema, or point them to a separate database. Does anyone have a working example of this?

Some time ago I was looking for a way to customize the schema and found a solution within JPA: snippets/axon-customized-jpa at master · JohT/snippets · GitHub

I’m not sure if this works for you. It might behave different for different JPA provider. Since it contains axon entity class names it may need to changed whenever these classes get changed (coupling), whereas I guess they are pretty stable

Hi @bgardner,

The tip from @JohT would be one of mine as well but I will expand a bit.

I haven’t tried it but the first thing that came to my mind would be to change the default schema for jpa, eg: That should do the trick but probably will also change the schema for all your other tables.

The seconf tip would be the same as before, use a orm.xml to do it for you.
Something like this (found on internet) might do the trick - again, I haven’t tried it myself.

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

    <!-- Axon needs these tables -->

    <entity class="org.axonframework.eventsourcing.eventstore.jpa.DomainEventEntry"/>
    <entity class="org.axonframework.eventsourcing.eventstore.jpa.SnapshotEventEntry"/>
    <entity class="org.axonframework.modelling.saga.repository.jpa.AssociationValueEntry"/>
    <entity class="org.axonframework.eventhandling.tokenstore.jpa.TokenEntry"/>
    <entity class="org.axonframework.modelling.saga.repository.jpa.SagaEntry"/>


Other than that, going for option 1 and using jpa configs might be the easiest and best approach if you are going to use the same database for storing events but also projections. If you go that route, please take them as if they were 2 different databases hence creating 2 connections (and pools), etc

Edit1: This post I found on stackoverflow can also give you extra ideas and guidance