Troubleshooting instanciating JPA Entity Manager as Spring Bean with Axon

I would like to configure the Axon Entity Manager with JPA als Bean, like:

@Configuration`Preformatted text`
class EntityManagerBean {
    @Bean
    fun dataSource(): DataSource {
        return EmbeddedDatabaseBuilder()
            .setType(EmbeddedDatabaseType.H2)
            .build()
    }

    @Bean
    @DependsOn("dataSource")
    fun entityManagerFactory(@Autowired dataSource: DataSource): LocalContainerEntityManagerFactoryBean {
        val entityManagerFactoryBean = LocalContainerEntityManagerFactoryBean()
        entityManagerFactoryBean.dataSource = dataSource
        entityManagerFactoryBean.setPackagesToScan("org.example.springkotlinrestfulapisample.command.jobfunction")
        entityManagerFactoryBean.persistenceUnitName = "JobFunction"
        entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider::class.java)
        entityManagerFactoryBean.jpaVendorAdapter = HibernateJpaVendorAdapter()
        return entityManagerFactoryBean
    }

    @Bean
    @DependsOn("entityManagerFactory")
    fun entityManager(@Autowired entityManagerFactory: LocalContainerEntityManagerFactoryBean): EntityManager {
        return entityManagerFactory.createNativeEntityManager(mapOf<String, String>())
    }
}

I get the error:

EntityManagerFactory interface [interface org.hibernate.SessionFactory] seems to conflict with Spring's EntityManagerFactoryInfo mixin - consider resetting the 'entityManagerFactoryInterface' property to plain [jakarta.persistence.EntityManagerFactory]

If I do so like:

@Configuration
class EntityManagerBean {

    @Bean
    fun entityManagerFactory(): EntityManagerFactory {
        return Persistence.createEntityManagerFactory("default")
    }

    @Bean
    @DependsOn("entityManagerFactory")
    fun entityManager(@Autowired entityManagerFactory: EntityManagerFactory): EntityManager {
        return entityManagerFactory.createEntityManager()
    }
}

I get the error:

No Persistence provider for EntityManager named default

Hope you could help me solve my issue.

Hi Christopher,

I’m not sure what the problem is. Might it be related to some incompatibility with the javaxjakarta rename? Which version of Spring (Boot) are you using? What specifically would you like to customize?