GiftCard Demo App and JpaEventStorageEngine for EmbeddedEventStore

Hi ,
I am new to Axon. I try to use JpaEventStorageEngine and EmbeddedEventStore in Axon Demo GiftCard App.What I must change in pom/properties/java code (step by step) for MySql or Postgress as EventStore?
Can anybody help me by samle?

Hello and welcome Max,

I don’t have a sample handy (maybe someone does) but I wander if you have tried to follow the docs. It is almost a step by step explanation of the things you have to configure. In case you haven’t tried that, please do. If you did tried it (or when you do) and you faced issues, or there is something unclear or missing, … do not hesitate to report/ask here.

Thanks Milen,
yes I tryed doc at reference
and I have this error:

    2021-01-22 12:47:45.664  WARN 16900 --- [ftcard.query]-0] o.a.e.TrackingEventProcessor             : Fetch Segments for Processor 'io.axoniq.demo.giftcard.query' failed: org.hibernate.hql.internal.ast.QuerySyntaxException: DomainEventEntry is not mapped [SELECT MIN(e.globalIndex) - 1 FROM DomainEventEntry e]. Preparing for retry in 32s
Hibernate: select tokenentry0_.segment as col_0_0_ from token_entry tokenentry0_ where tokenentry0_.processor_name=? order by tokenentry0_.segment ASC

My pom:

        <!-- Axon -->
        <dependency>
            <groupId>org.axonframework</groupId>
            <artifactId>axon-spring-boot-starter</artifactId>
            <version>${axon.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.axonframework</groupId>
                    <artifactId>axon-server-connector</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>${postgresql.version}</version>
        </dependency>

My EventStoreConfig.java:

package io.axoniq.demo.giftcard.command;

import org.axonframework.common.jdbc.PersistenceExceptionResolver;
import org.axonframework.common.jpa.EntityManagerProvider;
import org.axonframework.common.transaction.TransactionManager;
import org.axonframework.eventsourcing.eventstore.EmbeddedEventStore;
import org.axonframework.eventsourcing.eventstore.EventStorageEngine;
import org.axonframework.eventsourcing.eventstore.EventStore;
import org.axonframework.eventsourcing.eventstore.jpa.JpaEventStorageEngine;
import org.axonframework.serialization.Serializer;
import org.axonframework.spring.config.AxonConfiguration;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class EventStoreConfig {

    @Bean
    public EmbeddedEventStore eventStore(EventStorageEngine storageEngine, AxonConfiguration configuration) {
        return EmbeddedEventStore.builder()
                .storageEngine(storageEngine)
                .messageMonitor(configuration.messageMonitor(EventStore.class, "eventStore"))
                .build();
    }

    @Bean
    public EventStorageEngine storageEngine(Serializer defaultSerializer,
                                            PersistenceExceptionResolver persistenceExceptionResolver,
                                            @Qualifier("eventSerializer") Serializer eventSerializer,
                                            AxonConfiguration configuration,
                                            EntityManagerProvider entityManagerProvider,
                                            TransactionManager transactionManager) {
        return JpaEventStorageEngine.builder()
                .snapshotSerializer(defaultSerializer)
                .upcasterChain(configuration.upcasterChain())
                .persistenceExceptionResolver(persistenceExceptionResolver)
                .eventSerializer(eventSerializer)
                .entityManagerProvider(entityManagerProvider)
                .transactionManager(transactionManager)
                .build();
    }
}

What wrong I do? I must simply delete class EventStoreConfig?

Seems like your JPA is not properly configured.
Have you seen this post: DomainEventEntry is not mapped

I new member, and I can’t put my application.properties or picture into replay. :frowning:

I delete config java class and get state and events in one persistent JPA.

Now I think about them - how I can put events separatly from state.
I want make one persistent JPA for EvetnStore and second persistent JPA for sate in GiftCard Demo App.

To be honest with you, I don’t understand what do you mean.
Event store is where all the events are stored. Leaving aside segments for a moment, all apps connected to the same event store will be able to store/retrieve events from it. In that sense Event store IS the database fro events. It can be backed by database but it does not have to. For example AxonServer is another event store.

So your statement

I want make one persistent JPA for EvetnStore and second persistent JPA for sate in GiftCard Demo

does not make sense for event sourced aggregate(s) in GiftCard demo. The only thing you need to configure is the event store and the state of the aggregate(s) will be constructed from those events when needed.

Or do you want to change GiftCard demo to use State Stored Aggregate instead of event sourced one?

In GiftCard App I want to split on 2 JPA store.
First for event sourced aggregate as domain_event_entry (eventStore persistence JPA) and second store for data class CardSummary (state projection persistence JPA).

Ah the projections you mean. That makes sense now. I got confused by the word “state” as projections are not considered “state” in event sourced systems. Projections are just some specific view of some parts of the system useful for querying purposes. The state however is always calculated from the events.

For that I believe it’s sufficient to have 2 different persistence units. For example dedicated one for the event store and default one for the projections.

The JpaEventStorageEngine docs (see the link in my first response) contains examples how to use specific persistence context for the event store.

Here is example config:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
    <persistence-unit name="eventStorePersistenceUnit" transaction-type="RESOURCE_LOCAL"> (1)
        <class>org...eventstore.jpa.DomainEventEntry</class> (2)
        <class>org...eventstore.jpa.SnapshotEventEntry</class>
    </persistence-unit>
</persistence>

and an EntityManagerProvider that provides EntityManager for that unit:

public class MyEntityManagerProvider implements EntityManagerProvider {

    private EntityManager entityManager;

    @Override
    public EntityManager getEntityManager() {
        return entityManager;
    }

    @PersistenceContext(unitName = "eventStorePersistenceUnit")
    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

Have you tried that?

  1. persistence.xml
  1. application.properties

But I see all tables in one schema in my-db database:

What wrong I do?