Axon - MySql 的 JPA 事件存储

Axon - JPA Event store for MySql

我正在尝试使用 JPA 事件存储和 mysql 数据库来实现 Axon 应用程序。 Hibernate 会自动生成所有 tables,到目前为止它工作正常。

我的问题是 - 我可以用 Mysql 中的 AUTO_INCREMENT 列替换 hibernate_sequence mysql table 吗?我想为了做到这一点,我需要修改 Axon 的源代码,因为我找不到其他可配置的方法来修改域事件 @Entity 或其他实体的 @Id 注释?

更新

好的,我设法通过使用以下代码将新文件放入 src\main\resources\META-INF\orm.xml 来做到这一点:

<?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">

    <mapped-superclass class="org.axonframework.eventhandling.AbstractSequencedDomainEventEntry" access="FIELD">
        <attributes>
            <id name="globalIndex">
                <generated-value strategy="IDENTITY"/>
            </id>
        </attributes>
    </mapped-superclass>

    <entity class="org.axonframework.modelling.saga.repository.jpa.AssociationValueEntry" access="FIELD">
        <attributes>
            <id name="id">
                <generated-value strategy="IDENTITY"/>
            </id>
        </attributes>
    </entity>

</entity-mappings>

您可以通过代码进行此调整,没错。 然而,在您的项目中指定一个 orm.xml 文件更直接,对于某些 table(我假设您的场景中的 domain_event_entry table)可以调整某些列。 在那里你应该能够将序列发生器调整到你想要的样子。

希望对您有所帮助!