multi EntityManager with Spring Boot, but 'Too many persistable types (>10)

#1

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();
            }
        };
    }
}

 

#2

The free version of ObjectDB is limited to 10 entity classes per database.

See details here:

https://www.objectdb.com/database/purchase

ObjectDB Support
#3

of course I hava a license. (site license)

#4

The exception indicates that ObjectDB cannot find the activation code in the configuration file. 

See this manual page, regarding where ObjectDB searches for the configuration file.

Is it a specific issue with using ObjectDB Spring Boot? Can you run ObjectDB on the same computer otherwise?

ObjectDB Support
#5

I'm now debugging, so two database and app are running in a local machine.
single use of database1(6136) from app is ok.
single use of database2(6137) from app is also ok.
each objectdb.conf is same without port setting.
(activation code is same.)
any suggestions?

#6

See this manual page, regarding where ObjectDB searches for the configuration file.

Probably the application in which the licence doesn't work cannot find the configuration.

ObjectDB Support
#7

I'm trying with jpaproperties but I can't solve this problem.

> Chapter 6 - Configuration
> System.setProperty("objectdb.conf", "/my/objectdb.conf");
when dealing with two databases from one application, what should I do ?

 

#8

One trick that you can try, is to embed the configuration file in the objectdb.jar file, replacing the default configuration file that is loaded as a resource from objectdb.jar if no other configuration is found.

ObjectDB Support
#9

Solved with your trick.
Thanks a lot.

Reply