I'm trying to use two EntityManager with Spring Boot, but no luck with 'Too many persistable types (>10) - exceeds evaluation limit' at second database.
My purpose is converting database (converting model entity. same class name but different package).
Single application with Spring-Boot 2.1.8, and two objectdb server with different port.
My JPA configuration is
@Configuration @EnableJpaRepositories(basePackageClasses = RepositoryService.class, transactionManagerRef = "transactionManager", entityManagerFactoryRef = "entityManagerFactory1" ) @EntityScan(basePackageClasses = Shop.class) @ConfigurationProperties(prefix = "javax.persisitence.jdbc") public class JpaConfig { @Value("${javax.persistence.jdbc.url}") public String url; @Value("${javax.persistence.jdbc.user}") private String user; @Value("${javax.persistence.jdbc.password}") private String password; @Value("${javax.persistence.jdbc.persistenceUnitName}") private String persistenceUnitName; @Bean(name = "dataSource") @ConfigurationProperties(prefix = "javax.persistence.jdbc") public DataSource dataSource() { return DataSourceBuilder.create().build(); } @Primary @Bean(name = "entityManagerFactory1") public LocalContainerEntityManagerFactoryBean entityManagerFactory( @Qualifier("dataSource") DataSource dataSource, @Qualifier("jpaVendorAdapter") JpaVendorAdapter vendorAdapter ) { LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); Properties props = new Properties(); props.put("javax.persistence.jdbc.url",url); props.put("javax.persistence.jdbc.user",user); props.put("javax.persistence.jdbc.password",password); entityManagerFactoryBean.setJpaProperties(props); entityManagerFactoryBean.setDataSource(dataSource); entityManagerFactoryBean.setJpaVendorAdapter(vendorAdapter); entityManagerFactoryBean.setPackagesToScan(Shop.class.getPackage().getName()); entityManagerFactoryBean.setPersistenceUnitName("unit1"); entityManagerFactoryBean.afterPropertiesSet(); return entityManagerFactoryBean; } @Bean(name = "transactionManager") public PlatformTransactionManager transactionManager(@Qualifier("entityManagerFactory1") LocalContainerEntityManagerFactoryBean entityManagerFactory) { JpaTransactionManager transactionManager = new JpaTransactionManager(); transactionManager.setEntityManagerFactory(entityManagerFactory.getObject()); return transactionManager; } @Bean(name = "jpaVendorAdapter") JpaVendorAdapter jpaVendorAdapter() { return new AbstractJpaVendorAdapter() { @Override public PersistenceProvider getPersistenceProvider() { return new com.objectdb.jpa.Provider(); } }; } } JpaConfig2.java @Configuration @EnableJpaRepositories(basePackageClasses = RepositoryService2.class, transactionManagerRef = "transactionManager2", entityManagerFactoryRef = "entityManagerFactory2" ) @EntityScan(basePackageClasses = Shop.class) @Slf4j public class JpaConfig2 { @Value("${javax.persistence.jdbc2.url}") public String url; @Value("${javax.persistence.jdbc2.user}") private String user; @Value("${javax.persistence.jdbc2.password}") private String password; @Value("${javax.persistence.jdbc2.persistenceUnitName}") private String persistenceUnitName; @Bean(name = "dataSource2") @ConfigurationProperties(prefix = "javax.persistence.jdbc2") public DataSource dataSource() { return DataSourceBuilder.create().build(); } @Bean(name = "entityManagerFactory2") public LocalContainerEntityManagerFactoryBean entityManagerFactory( @Qualifier("dataSource2") DataSource dataSource, @Qualifier("jpaVendorAdapter2") JpaVendorAdapter vendorAdapter ) { LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); Properties props = new Properties(); props.put("javax.persistence.jdbc.url",url); props.put("javax.persistence.jdbc.user",user); props.put("javax.persistence.jdbc.password",password); entityManagerFactoryBean.setJpaProperties(props); entityManagerFactoryBean.setDataSource(dataSource); entityManagerFactoryBean.setJpaVendorAdapter(vendorAdapter); entityManagerFactoryBean.setPackagesToScan(RepositoryService2.class.getPackage().getName()); entityManagerFactoryBean.setPersistenceUnitName("unit2"); entityManagerFactoryBean.afterPropertiesSet(); return entityManagerFactoryBean; } @Bean(name = "transactionManager2") public PlatformTransactionManager transactionManager(@Qualifier("entityManagerFactory2") LocalContainerEntityManagerFactoryBean entityManagerFactory) { JpaTransactionManager transactionManager = new JpaTransactionManager(); transactionManager.setEntityManagerFactory(entityManagerFactory.getObject()); return transactionManager; } @Bean(name = "jpaVendorAdapter2") JpaVendorAdapter jpaVendorAdapter() { return new AbstractJpaVendorAdapter() { @Override public PersistenceProvider getPersistenceProvider() { return new com.objectdb.jpa.Provider(); } }; } }