spring-boot, axon 3, postgres = ERROR: sequence "hibernate_sequence" does not exist plus multitenant

Hello guys. Good evening.

First of all: does axon works with multitenant?

It’s not creating my tables. So I decide start a new simple application just to check the DDLs. Now, its creating my tables but i got:

ERROR: sequence “hibernate_sequence” does not exist

I know I could just create that sequence manually but I want to know if I can customize the sequences names or something like that.

Also, since Im using liquibase, I would like to know if theres a formal documentation with axon table’s DDLs.

PS: Im using spring-boot 1.5.2, axon 3, postgres.

I dont like one table using a generic ‘hibernate_sequence’

Hibernate: select nextval (‘hibernate_sequence’)
Hibernate: insert into domain_event_entry (event_identifier, meta_data, payload, payload_revision, payload_type, time_stamp, aggregate_identifier, sequence_number, type, global_index) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
44ad4b20-ae9c-41eb-9d6c-cab634455639

Hi Mike,

there are different ways to implement multi-tenancy in Axon. If you use multitenancy on the datasource level, there are some restrictions, though. The TrackingProcessor, for example, doesn’t support this (yet). The rest of the components should not have any issues.

If you use Hibernate/JPA, you can override any configuration defined by annotations. I haven’t used it myself, but apparantly there are ways (using XML, though) to override the definitions.
Alternatively, you can extend the JpaEventStorageEngine and implement the domainEventEntryEntityName and createEventEntity methods. This allows you to use your own entities. Note that these entities must have the same properties defined as the original Axon entities. Some projects use this to add additional columns to the event store, or -just like what you’d want- change some of the properties that are generated by default.

Hope this helps.
Cheers,

Allard

Hi Allard, nice to meet you.

I have been watching your live code demos for a long time by now. It’s like I know you. Lol

PS: sorry about my bad english.

there are different ways to implement multi-tenancy in Axon. If you use multitenancy on the datasource level, there are some restrictions, though. The TrackingProcessor, for example, doesn’t support this (yet). The rest of the components should not have any issues.

We are using tenancy with database SCHEMA. New schemas are created on ‘fly’ with liquibase by just passing few extra information on HEADERs request. This allow us to create a new database for a new client without any redeploy/restart.

spring.jpa.properties.hibernate.multiTenancy=SCHEMA
spring.jpa.properties.hibernate.tenant_identifier_resolver=br.com.zup.realwave.common.tenant.context.CurrentTenantIdentifier
spring.jpa.properties.hibernate.multi_tenant_connection_provider=br.com.zup.realwave.common.tenant.provider.PostgreSqlMultiTenantConnectionProvider

I couldnt make Axon 3 create my tables alone in this case. I’m not sure if is my fault and I missing some configuration tho. Well, not a big problem, I just started one simply Axon Springboot app at start.spring.io without no tenancy and I copy past the DDL to my liquibase changelog files. Still I’m worry about what I will do when Axon change the DDLs.

If you use Hibernate/JPA, you can override any configuration defined by annotations. I haven’t used it myself, but apparantly there are ways (using XML, though) to override the definitions.
Alternatively, you can extend the JpaEventStorageEngine and implement the domainEventEntryEntityName and createEventEntity methods. This allows you to use your own entities. Note that these entities must have the same properties defined as the original Axon entities. Some projects use this to add additional columns to the event store, or -just like what you’d want- change some of the properties that are generated by default.

In that simple SB + Axon 3 app that I used to copy the DDL, I can see the ‘hibernate_sequence’ created if I have this option on my application.properties so the app runs fine.

spring.jpa.hibernate.ddl-auto=create

Still, I really dont like this. I will dig a little more to try make the DomainEventEntry (and others tables) use his own sequence, and the others tables too. Override JpaEventStorageEngine looks too much, idk.

Anyway, as a suggestion, I would ask you guys (maybe I could help) to add the DDL info in the official Axon’s documentation page.

Thank you so much for the answer, Allard. Really.

The xml map you suggest works perfectly.

META-INF/orm.xml

<?xml version="1.0" encoding="UTF-8"?>

<entity-mappings
        xmlns="http://java.sun.com/xml/ns/persistence/orm"
        version="2.0">
    <mapped-superclass class="org.axonframework.eventsourcing.eventstore.AbstractSequencedDomainEventEntry" access="FIELD">
        <attributes>
            <id name="globalIndex">
                <column name="global_index"/>
                <generated-value generator="generator" strategy="SEQUENCE"/>
                <sequence-generator name="generator" sequence-name="domain_event_entry_seq" allocation-size="1"/>
            </id>
        </attributes>
    </mapped-superclass>
</entity-mappings>