我正在尝试使用 JPA 事件存储和 mysql 数据库实现 Axon 应用程序。 Hibernate 会自动生成所有表,目前为止一切正常。
我的问题是 - 我可以为 Mysql 中的 AUTO_INCREMENT
列替换 hibernate_sequence mysql 表吗?我想为了做到这一点,我需要修改 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
文件更直接,对于某些表(我假设您的方案中的 domain_event_entry
表)可以调整某些列。
在那里,您应该能够将序列生成器调整到您想要的样子。
希望这对您有所帮助!
关于java - Axon - MySql 的 JPA 事件存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55081038/