We would like to store some aggregates as state stored aggregates. But we are not satisfied with the axon state stored aggregates with hibernate. We would like to implement a hexagonal architecture without technical aspects (other that axon itself) in the domain. Hibernate entity structure often opposes to the structure of a domain focussed domain entity. And hibernate annotations pollute the aggregate. So hibernate does not fit our needs.
I have to mention that we have a SQL Database and it is not an option to switch to a NoSQL database…
A naive way woud be to have a command handler that
- loads a hibernate entity,
- handles it to a converter to get a technology-free aggregate,
- hands over the command to that aggregate,
- converts it back to a hibernate entity
- stores the changes
- publishes events that the aggregate might have produced (one chellange here is to get the correct sequence number)
But this solution has much boylerplate code, bypasses much of axon framework, is not safe for concurrent comands as axon aggregates and it’s not possible to publish a domain event from that aggregate or use @EventHandler logic (wich we also have to do).
My question is: Is there a axon conform way to implement and plug-in e.g. an Aggregate Loading/Saving Component that integrates well into Axon so that we can specify how the aggregate is mapped to the persistence layer?