How to configure HybridJpaRepository

Hi,

I am using Axxon 2.4.2 with JPA/Spring.

I have a working configuration of the EventSourcingRepository:

<axon:event-sourcing-repository
id=“myEntityRepository”
aggregate-type=“nl.dsen.MyEntity”
event-bus=“eventBus”
event-store=“eventStore”/>

I want to change this to use the HybridJpaRepository, but I am running into some issues.

I changed the configuration to:

Now, how should I configure first constructor argument to the HybridJpaRepository bean? Should I create custom EntityManagerProvider? I tried that route but ran into an Exception:

WARN [2015-09-11 15:52:16,675] org.axonframework.commandhandling.callbacks.LoggingCallback: Command resulted in exception: nl.dsen.zmag.domain.zaak.CreateZaakCommand
! javax.persistence.TransactionRequiredException: no transaction is in progress
! at org.hibernate.jpa.spi.AbstractEntityManagerImpl.checkTransactionNeeded(AbstractEntityManagerImpl.java:1136)
! at org.hibernate.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1297)

A pointer to some examples would be helpfull.

Thanks for a great framework so far.

Best, Thomas

Hi Thomas,

JPA requires you to have a transaction when performing update queries. Do you have a transaction manager (of transaction interceptor) configured on your command bus?
You can use an instance of ContainerManagedEntityManagerProvider as the first constructor arg in this configuration. It will force Axon to use Spring’s entity manager instance.

Cheers,

Allard

Hi Allard

thanks for the quick reply.

I don’t see why your configuration doesn’t support a ContainerManagedEntityManagerProvider. The ContainerManagedEntityManagerProvider contains an EntityManager annotated with @PersistenceContext, which Spring will happily inject.

Cheers,

Allard

Yes, adding a ContainerManagedEntityManagerProvider to my Spring
configuration and passing it as the first constructor argument to
the HybridJpaRepository solved the issue.

Best,

Thomas