Hello I have this problem with my spring boot application:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dbEntityManagerFactory' defined in class path resource ...: EntityManagerFactory interface [interface org.hibernate.SessionFactory] seems to conflict with Spring's EntityManagerFactoryInfo mixin - consider resetting the 'entityManagerFactoryInterface' property to plain [jakarta.persistence.EntityManagerFactory]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:600)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1231)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:949)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:334)
at org.springframework.boot.test.context.SpringBootContextLoader.lambda$loadContext$3(SpringBootContextLoader.java:137)
at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:58)
at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:46)
at org.springframework.boot.SpringApplication.withHook(SpringApplication.java:1454)
at org.springframework.boot.test.context.SpringBootContextLoader$ContextLoaderHook.run(SpringBootContextLoader.java:553)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:137)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:108)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:225)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:152)
... 17 more
My pom.xml connected dependencies are:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.3</version>
<relativePath/>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.2.0-M1</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.2</version>
</dependency>
</parent>
And this is my DatabaseConfiguration class:
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(entityManagerFactoryRef = "dbEntityManagerFactory", transactionManagerRef = "dbTransactionManager", basePackages = {
"..."})
@EntityScan("...")
@RequiredArgsConstructor
public class DatabaseConfiguration {
private final YamlProperties yamlProperties;
@Bean(name = "dbDataSourceProperties")
@ConfigurationProperties("spring.datasource")
public DataSourceProperties dbDataSourceProperties() {
return new DataSourceProperties();
}
@Bean(name = "dbDataSource")
public DataSource dataSource(@Qualifier("dbDataSourceProperties") DataSourceProperties dbDataSourceProperties) {
return dbDataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
}
@Bean(name = "dbEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
@Qualifier("dbDataSource") DataSource dbDataSource) {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dbDataSource);
Properties properties = new Properties();
properties.setProperty("hibernate.hbm2ddl.auto", "update");
properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
properties.setProperty("hibernate.connection.url", getDatabaseUrl());
properties.setProperty("hibernate.default_schema", "CCN2_SCHEMA");
em.setJpaProperties(properties);
em.setPackagesToScan("eu.europa.ec.taxud.ssv.earchiving_archiving_agent_kibana_pdf_recovery.repository.model");
em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
em.setPersistenceUnitName("dbDataSource");
return em;
}
@Bean(name = "dbTransactionManager")
public PlatformTransactionManager dbTransactionManager(
@Qualifier("dbEntityManagerFactory") EntityManagerFactory dbEntityManagerFactory) {
return new JpaTransactionManager(dbEntityManagerFactory);
}
public String getDatabaseUrl() {
return String.format(
"%s;USER=%s;PASSWORD=%s;DATABASE_TO_LOWER=true;INIT=CREATE SCHEMA IF NOT EXISTS CCN2_SCHEMA;",
yamlProperties.getAppProperties().getDatabaseProperties().getSpringDatasourceUrl(),
yamlProperties.getAppProperties().getDatabaseProperties().getSpringDatasourceUsername(),
yamlProperties.getAppProperties().getDatabaseProperties().getSpringDatasourcePassword());
}
}
Is it the problem with versions of spring boot and jakarta dependencies? Right now they are both the newest I tried some conifugrations but it didn't work. Before i had older version of springboot and javax instead of jakarta and it was working pretty well, but now I need them to be relatively the newest