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: spring.jpa.properties.hibernate.default_schema=another_schema. 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"?>
<entity-mappings
        xmlns="http://java.sun.com/xml/ns/persistence/orm"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
        http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
        version="2.0">

    <!-- Axon needs these tables -->

    <schema>axon</schema>
    <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"/>

</entity-mappings>

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

KR,