How to disable spring hibernate generate-ddl only for Axon tables?

Hi all,

I am using axon in a very simple way with spring boot, here are my dependencies:

<!-- Axon -->
<dependency>
    <groupId>org.axonframework</groupId>
    <artifactId>axon-spring-boot-starter</artifactId>
    <version>4.2.1</version>
    <exclusions>
        <exclusion>
            <groupId>org.axonframework</groupId>
            <artifactId>axon-server-connector</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.axonframework</groupId>
            <artifactId>axon-disruptor</artifactId>
        </exclusion>
    </exclusions>
</dependency>

And here is my autoconfiguration for spring;

Hi Gustavo,

if you use autoconfiguration of JPA, then you’ll get all potentially relevant tables created for you. The point is that Axon isn’t able to know yet what you’ll be using.
You can override this by defining which entities you want to map to tables. You do this by specifying an @EntityScan annotation on one (or more) of your Spring Configuration classes. Once you explicitly define which classes to include, Axon will no longer define default. If you do use some of the Axon entities, you will need to explicitly include them in the @EntityScan as well.

Hope this helps.
Cheers,

Hi Allard Buijze, thank you for the answer.

I found some posts on the internet for this issue (where you are envolved as well), and gathering all i could find, i tried this:

@SpringBootApplication(scanBasePackages = {"com.ases.shopping.order.*"})
@EntityScan(basePackages = {
        "com.ases.shopping.order.*",
        "org.axonframework.eventsourcing.eventstore.jpa",
        "org.axonframework.eventhandling.saga.repository.jpa",
        "org.axonframework.eventhandling.tokenstore.jpa"
})
@ImportResource("classpath*:beans.xml")
public class OrderApplication {

But, i am getting the error:

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: SagaEntry is not mapped

Did i do it right?

Thanks in advance!

Hi again Allard,

After taking a look at the post:
https://groups.google.com/forum/#!topic/axonframework/RfYU6Uwt4NA

I added the org.axonframework.modelling.saga.repository.jpa to the entity scan, and now the application is running.
But, my main goal of not creating the entry tables was not achieved, as all the tables are still being created (association_value_entry, domain_event_entry, snapshot_event_entry, token_enttry).

I do not have any axon entities, my entities are using the default java persistence @Entity annotation.

My idea was to use the SimpleEventBus and the CommandGateway only for achieving (in a very simple manner) the command pattern to work.

If i could ignore those basePackages for axon without having any errors it would be nice! I don´t know if axon was built making this possible.

Thank you very much for your time!

Hi Gustavo,

I checked the code for the JpaSagaStore, and it seems that the queries in there are eagerly created and registered as names queries. Unfortunately, this process fails if SagaEntry is not mapped as an entity.
If you don’t actually use the Saga store, there is no problem if the table doesn’t actually exist. I don’t think Hibernate auto-ddl allow you to selectively create tables for entities.

I’ll have a look at whether we can lazily create the named queries, to not cause exceptions when the entity is unmapped.

Cheers,