0

I want to use Axon Framework and Axon Server as my event store and event bus along side with spring boot project that include spring data jpa.

I have a docker-compose that starts 2 containers - postgres db and Axon Server. I don't want axon to use postgres as it event store, I want it to use Axon Server as event store. So I add @EntityScan to main class to point to my own JPA entities and when I start my spring boot app I get the following exception:

Caused by: java.util.concurrent.ExecutionException: org.axonframework.lifecycle.LifecycleHandlerInvocationException: Failed during invocation of lifecycle handler [public void org.axonframework.axonserver.connector.processor.EventProcessorControlService.start()] on component [org.axonframework.axonserver.connector.processor.EventProcessorControlService@32f2de5c]

Caused by: org.axonframework.lifecycle.LifecycleHandlerInvocationException: Failed during invocation of lifecycle handler [public void org.axonframework.axonserver.connector.processor.EventProcessorControlService.start()] on component [org.axonframework.axonserver.connector.processor.EventProcessorControlService@32f2de5c]

Caused by: java.lang.reflect.InvocationTargetException: null

Caused by: org.axonframework.eventhandling.tokenstore.UnableToRetrieveIdentifierException: Exception occurred while trying to establish storage identifier

Caused by: java.lang.IllegalArgumentException: Unable to locate persister: org.axonframework.eventhandling.tokenstore.jpa.TokenEntry

Caused by: org.hibernate.UnknownEntityTypeException: Unable to locate persister: org.axonframework.eventhandling.tokenstore.jpa.TokenEntry

before I added all the JPA dependency it worked fine but after I added spring-boot-starter for jpa I got the above exception

How can I fix it?

Lucas Campos
  • 1,860
  • 11
  • 17
user1409534
  • 2,140
  • 4
  • 27
  • 33

2 Answers2

0

By default, Axon Framework will try to create some tables on your postgres. Those tables are needed to manage your Token, Sagas, etc. Since you added an @EntityScan annotation, the default scanning mechanism in place is no longer going to work.

You can quickly check on its ref guide how to fix your problem.

Quoting from the docs:

To register Axon's JPA Entities, include the relevant packages, as described below:

  • org.axonframework.eventhandling.tokenstore contains the entities necessary for the TokenStore used by Event Processors.
  • org.axonframework.modelling.saga.repository.jpa contains the entities necessary to persist Sagas
  • org.axonframework.eventsourcing.eventstore.jpa contains the entities necessary for the JPA Event Storage engine, when using a relational database as the Event Store.
Lucas Campos
  • 1,860
  • 11
  • 17
  • Thanx for answering. The thing is that I don't want relational database to act as the Event Store. I want Axon server to be my event store. Do I still need to above? – user1409534 Sep 14 '21 at 18:26
  • 1
    The first two has nothing to do with Event Store but to do on how the Framework works! The last one is about Event Store and you can skip that one in this case. – Lucas Campos Sep 14 '21 at 19:19
  • I see thank you. I added the first 2 packages and got org.postgresql.util.PSQLException: ERROR: relation "token_entry" does not exist – user1409534 Sep 14 '21 at 19:28
  • See if it helps you: https://stackoverflow.com/questions/29087626/entity-class-name-is-transformed-into-sql-table-name-with-underscores ... it is some spring-data configuration you need to get properly since you are not using all the auto-configuration things anymore. – Lucas Campos Sep 14 '21 at 20:52
  • To add to that, the default name of the entity on AxonFramework is `TokenEntry` but Spring, by default, will translate that into `token_entry` which will fail as you could see. – Lucas Campos Sep 14 '21 at 21:08
  • I see. Thank you. by the way even if I drop the @EntityScan and try use Axon out of the box with all its autoconfiguration I still get relation "token_entry" does not exist – user1409534 Sep 14 '21 at 21:26
0

I manage to get it work as follows:

I remove @EntityScan and use autoconfig to scan all entites

I add to application.properties file

spring.jpa.hibernate.ddl-auto=update

and all tables in the database that axon needs are there.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
user1409534
  • 2,140
  • 4
  • 27
  • 33