【问题标题】:Axonframework doesn't insert event data with jpaAxonframework 不使用 jpa 插入事件数据
【发布时间】:2014-12-30 19:29:35
【问题描述】:

我运行了入门指南 (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>

【问题讨论】:

  • 您能提供更多信息吗?喜欢你得到的错误日志吗?

标签: axon


【解决方案1】:

ATM 将 JPA 与 Axon 一起使用需要 Spring。为 Axon TransactionManager 提供的唯一实现是 SpringTransactionManager,它需要一个 org.springframework.orm.jpa.JpaTransactionManager 的实例。见JpaEventStore and resource local transactions:很旧,但似乎仍然有效。

我所说的 Spring 不仅是指 Spring-orm,还包括 Spring-context 和 Spring-aspects。如果没有所有 Spring 魔法,我还没有找到如何使用 JpaTransactionManager。

两个例子:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-02
    • 2014-04-11
    • 1970-01-01
    相关资源
    最近更新 更多