Hello,
first: What is this error message: “Title seems unclear, one or more words is very long?” What does it want to tell me?
Original title should be: “Implementing an Entity- /Transaction-manager compatible with JGroups (LocalContainerEntityManagerFactoryBean)”
I have the following beans as part of a Spring persistence context configuration:
@Bean
private HibernateJpaVendorAdapter vendorAdaptor() {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setShowSql(true);
return vendorAdapter;
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setJpaVendorAdapter(vendorAdaptor());
entityManagerFactoryBean.setDataSource(dataSource());
entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
entityManagerFactoryBean.setPackagesToScan(ENTITYMANAGER_PACKAGES_TO_SCAN);
entityManagerFactoryBean.setJpaProperties(jpaHibernateProperties());
return entityManagerFactoryBean;
}
@Bean
public PlatformTransactionManager transactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactoryBean().getObject());
return transactionManager;
}
How would I implement this in Axon ? Do I have to substitute all classes in here for Axon classes and just keep the dataSource bean ?
I am not using AxonServer and instead for distribution of the command processing I want to use the JGroup extension.
So first there are the classes and code-snippets named in the following link whereas, because I exclude AxonServer from the classpath, I have to implement an EmbeddedEventStore, dependent on a JpaEventStorageEngine, dependent on a JPA persistence-unit.
See docs.axoniq.io > Event Bus & Event Store > Embedded Event Store
It needs an EntityManagerProvider
. So I could proceed to subclass like this:
public class MyEntityManagerProvider implements ContainerManagedEntityManagerProvider {
private EntityManager entityManager;
@Override
public EntityManager getEntityManager() {
return entityManager;
}
@PersistenceContext(unitName = "myPersistenceUnit")
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
Then I would create a bean
@Bean
MyEntityManagerProvider entityManagerProvider() { ... }
BUT
The entry axon docs > Extensions > JGroups > Configuration in Spring (Boot) suggests to use org.axonframework.commandhandling.distributed.jgroups.JGroupsConnectorFactoryBean
But… for what? En lieu of LocalContainerEntityManagerFactoryBean
? The name sounds similar and it speaks about the ApplicationContext so it should have something to do with the EntityManager.
Can you please tell me if I should use this connector factory and how I intertwine it with the entitymanager ?
Do I have to change the Spring LocalEntityManagerFactoryBean for an Axon class that produces an own Axon EntityManager in order to use it ?
Thanks!
Yours sincerly
überSpotz