1

入門ガイド ( http://www.axonframework.org/axon-2-quickstart-guide/ ) を実行しましたが、問題なく動作します。

FileSystemEventStore を JpaEventStore に置き換えようとしましたが、イベントが保存されません。

ここに画像の説明を入力

これが私の構成です:

public static void main(String[] args) {
    CommandBus commandBus = new SimpleCommandBus();
    CommandGateway commandGateway = new DefaultCommandGateway(commandBus);
    //EventStore eventStore = new FileSystemEventStore(new SimpleEventFileResolver(new File("./events")));

    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory( "cqrsworkshop" );
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    SimpleEntityManagerProvider entityManagerProvider = new SimpleEntityManagerProvider(entityManager);
    EventStore eventStore = new JpaEventStore(entityManagerProvider);

    EventBus eventBus = new SimpleEventBus();
    EventSourcingRepository<ToDoItem> repository = new EventSourcingRepository<ToDoItem>(ToDoItem.class, eventStore);

    repository.setEventBus(eventBus);

    AggregateAnnotationCommandHandler.subscribe(ToDoItem.class, repository, commandBus);
    AnnotationEventListenerAdapter.subscribe(new ToDoEventHandler(), eventBus);

    final String itemId = UUID.randomUUID().toString();
    commandGateway.send(new CreateToDoItemCommand(itemId, "Need to do this"));
    commandGateway.send(new MarkCompletedCommand(itemId));

    entityManagerFactory.close();
}

   <persistence-unit name="cqrsworkshop">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <!-- JPA Event Store -->
            <class>org.axonframework.eventstore.jpa.DomainEventEntry</class>
            <class>org.axonframework.eventstore.jpa.SnapshotEventEntry</class>

            <properties>

                <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />

                <property name="javax.persistence.jdbc.url" value="jdbc:h2:~/test" />
                <property name="javax.persistence.jdbc.user" value="sa" />
                <property name="javax.persistence.jdbc.password" value="" />

                <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect " />
                <property name="hibernate.show_sql" value="true" />
                <property name="hibernate.hbm2ddl.auto" value="update" />
            </properties>
        </persistence-unit>
4

1 に答える 1