当前位置: 首页 > 知识库问答 >
问题:

使用来自不同数据库的bean Hibernate DuplicateMappingException

伯彦君
2023-03-14

编辑:我今天早上意识到这个异常似乎与Spring引导执行器有关,它似乎只在生产中运行,而不是在从Spring工具套件中启动prohect时运行。(请参见文章末尾的异常跟踪)

主数据库是使用jpa访问的,关于该数据库的所有内容都在一个特定的包中。

另一个数据库用于直接使用Hibernate访问遗留bean。关于那些遗留bean的一切都在一个不同的包中。

有些bean在两个包中具有相同的名称,但是由于它们是在两个不同的存储库中配置的,所以我认为这不会是一个问题。

    package fr.mycompany.dbconfprimary;

...
...

@Configuration
@EnableJpaRepositories(
        basePackages = "fr.mycompany.dbconfprimary",
        entityManagerFactoryRef = "entityManagerFactory",
        transactionManagerRef = "transactionManager",
        repositoryBaseClass = BaseRepositoryImpl.class)
public class HibernatePrimaryConfig {
    ...
    ...

    @Bean
    @Primary
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
        LocalContainerEntityManagerFactoryBean em
        = new LocalContainerEntityManagerFactoryBean();
        em.setDataSource(dataSource());
        em.setPackagesToScan(
                new String[] { "fr.mycompany.dbconfprimary" });

        HibernateJpaVendorAdapter vendorAdapter
        = new HibernateJpaVendorAdapter();
        em.setJpaVendorAdapter(vendorAdapter);
        HashMap<String, Object> properties = new HashMap<>();

        properties.put("hibernate.hbm2ddl.auto",ddlMode);
        properties.put("hibernate.dialect",dialect);
        em.setJpaPropertyMap(properties);

        return em;
    }

    @Primary
    @Bean
    public PlatformTransactionManager transactionManager() {

        JpaTransactionManager transactionManager
        = new JpaTransactionManager();
        transactionManager.setEntityManagerFactory(
                entityManagerFactory().getObject());
        return transactionManager;
    }

    @Primary
    @Bean("serversDataSource")
    public DataSource dataSource() {

        DriverManagerDataSource dataSource
          = new DriverManagerDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);

        return dataSource;
    }   

}

下面是辅助数据库的配置

    package fr.mycompany.dbconfsecondary;
...
...

@Configuration
@EnableJpaRepositories(
        basePackages = {"fr.mycompany.dbconfsecondary"}, 
        entityManagerFactoryRef = "secondaryEntityManagerFactory", 
        transactionManagerRef = "secondaryTransactionManager")
public class HibernateSecondaryConfig {
...
...

    @Bean
    public LocalContainerEntityManagerFactoryBean secondaryEntityManagerFactory() {
        LocalContainerEntityManagerFactoryBean em
        = new LocalContainerEntityManagerFactoryBean();
        em.setDataSource(secondaryDataSource());
        em.setPackagesToScan(
                new String[] {"fr.mycompany.dbconfsecondary");

        String[] hbmFiles=new String[hibernateHbmResources.length];
        for(int i=0;i<hibernateHbmResources.length;i++)
            try {
                hbmFiles[i]=convertHbmPath(hibernateHbmResources[i].getFile().getAbsolutePath());
            } catch (IOException e) {
                throw(new RuntimeException(e));
            }
        em.setMappingResources(hbmFiles);

        HibernateJpaVendorAdapter vendorAdapter
        = new HibernateJpaVendorAdapter();
        em.setJpaVendorAdapter(vendorAdapter);
        HashMap<String, Object> properties = new HashMap<>();

        properties.put("hibernate.hbm2ddl.auto",ddlMode);
        properties.put("hibernate.dialect",dialect);
        properties.put("hibernate.current_session_context_class","thread");

        em.setJpaPropertyMap(properties);

        return em;
    }

    @Bean
    public PlatformTransactionManager secondaryTransactionManager() {

        JpaTransactionManager transactionManager
        = new JpaTransactionManager();
        transactionManager.setEntityManagerFactory(
                secondaryEntityManagerFactory().getObject());
        return transactionManager;
    }

    @Bean("secondaryServersDataSource")
    public DataSource secondaryDataSource() {

        DriverManagerDataSource dataSource
          = new DriverManagerDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);

        return dataSource;
    }   
...
...

}

[几乎]完全异常跟踪:

2019-12-11 10:08:39 [main] ERROR
                                o.s.b.w.e.tomcat.TomcatStarter - Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]: Factory method 'healthContributorRegistry' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'applicationDiskUsage': Unsatisfied dependency expressed through field 'parameterService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'parameterService': Unsatisfied dependency expressed through field 'paramEnumerationRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'parametrageTypeEnumerationRepo': Cannot create inner bean '(inner bean)#255eadf5' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#255eadf5': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [fr/mycompany/ipolice/server/Hibernatev3Config.class]: Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: The [fr.mycompany.secondarydb.BeanName] and [fr.mycompany.primarydb.BeanName] entities share the same JPA entity name: [BeanName] which is not allowed!
2019-12-11 10:08:39 [main] INFO 
                                o.a.catalina.core.StandardService - Stopping service [Tomcat]
2019-12-11 10:08:39 [main] WARN 
                                o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2019-12-11 10:08:39 [main] INFO 
                                o.s.b.a.l.ConditionEvaluationReportLoggingListener - 
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-12-11 10:08:39 [main] ERROR
                                o.s.boot.SpringApplication - Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:156)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
    at fr.mycompany.Application.main(Application.java:41)
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:126)
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:88)
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:438)
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:191)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:180)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:153)
    ... 8 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]: Factory method 'healthContributorRegistry' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'applicationDiskUsage': Unsatisfied dependency expressed through field 'parameterService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'parameterService': Unsatisfied dependency expressed through field 'paramEnumerationRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'parametrageTypeEnumerationRepo': Cannot create inner bean '(inner bean)#255eadf5' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#255eadf5': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [fr/mycompany/ipolice/server/Hibernatev3Config.class]: Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: The [fr.mycompany.secondarydb.BeanName] and [fr.mycompany.primarydb.BeanName] entities share the same JPA entity name: [BeanName] which is not allowed!
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:656)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338)
...
    ... 13 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]: Factory method 'healthContributorRegistry' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'applicationDiskUsage': Unsatisfied dependency expressed through field 'parameterService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'parameterService': Unsatisfied dependency expressed through field 'paramEnumerationRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'parametrageTypeEnumerationRepo': Cannot create inner bean '(inner bean)#255eadf5' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#255eadf5': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [fr/mycompany/ipolice/server/Hibernatev3Config.class]: Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: The [fr.mycompany.secondarydb.BeanName] and [fr.mycompany.primarydb.BeanName] entities share the same JPA entity name: [BeanName] which is not allowed!
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]: Factory method 'healthContributorRegistry' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'applicationDiskUsage': Unsatisfied dependency expressed through field 'parameterService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'parameterService': Unsatisfied dependency expressed through field 'paramEnumerationRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'parametrageTypeEnumerationRepo': Cannot create inner bean '(inner bean)#255eadf5' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#255eadf5': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [fr/mycompany/ipolice/server/Hibernatev3Config.class]: Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: The [fr.mycompany.secondarydb.BeanName] and [fr.mycompany.primarydb.BeanName] entities share the same JPA entity name: [BeanName] which is not allowed!
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]: Factory method 'healthContributorRegistry' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'applicationDiskUsage': Unsatisfied dependency expressed through field 'parameterService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'parameterService': Unsatisfied dependency expressed through field 'paramEnumerationRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'parametrageTypeEnumerationRepo': Cannot create inner bean '(inner bean)#255eadf5' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#255eadf5': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [fr/mycompany/ipolice/server/Hibernatev3Config.class]: Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: The [fr.mycompany.secondarydb.BeanName] and [fr.mycompany.primarydb.BeanName] entities share the same JPA entity name: [BeanName] which is not allowed!
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]: Factory method 'healthContributorRegistry' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'applicationDiskUsage': Unsatisfied dependency expressed through field 'parameterService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'parameterService': Unsatisfied dependency expressed through field 'paramEnumerationRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'parametrageTypeEnumerationRepo': Cannot create inner bean '(inner bean)#255eadf5' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#255eadf5': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [fr/mycompany/ipolice/server/Hibernatev3Config.class]: Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: The [fr.mycompany.secondarydb.BeanName] and [fr.mycompany.primarydb.BeanName] entities share the same JPA entity name: [BeanName] which is not allowed!
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'applicationDiskUsage': Unsatisfied dependency expressed through field 'parameterService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'parameterService': Unsatisfied dependency expressed through field 'paramEnumerationRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'parametrageTypeEnumerationRepo': Cannot create inner bean '(inner bean)#255eadf5' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#255eadf5': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [fr/mycompany/ipolice/server/Hibernatev3Config.class]: Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: The [fr.mycompany.secondarydb.BeanName] and [fr.mycompany.primarydb.BeanName] entities share the same JPA entity name: [BeanName] which is not allowed!
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'parameterService': Unsatisfied dependency expressed through field 'paramEnumerationRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'parametrageTypeEnumerationRepo': Cannot create inner bean '(inner bean)#255eadf5' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#255eadf5': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [fr/mycompany/ipolice/server/Hibernatev3Config.class]: Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: The [fr.mycompany.secondarydb.BeanName] and [fr.mycompany.primarydb.BeanName] entities share the same JPA entity name: [BeanName] which is not allowed!
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'parametrageTypeEnumerationRepo': Cannot create inner bean '(inner bean)#255eadf5' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#255eadf5': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [fr/mycompany/ipolice/server/Hibernatev3Config.class]: Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: The [fr.mycompany.secondarydb.BeanName] and [fr.mycompany.primarydb.BeanName] entities share the same JPA entity name: [BeanName] which is not allowed!
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#255eadf5': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [fr/mycompany/ipolice/server/Hibernatev3Config.class]: Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: The [fr.mycompany.secondarydb.BeanName] and [fr.mycompany.primarydb.BeanName] entities share the same JPA entity name: [BeanName] which is not allowed!
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [fr/mycompany/ipolice/server/Hibernatev3Config.class]: Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: The [fr.mycompany.secondarydb.BeanName] and [fr.mycompany.primarydb.BeanName] entities share the same JPA entity name: [BeanName] which is not allowed!
Caused by: org.hibernate.DuplicateMappingException: The [fr.mycompany.secondarydb.BeanName] and [fr.mycompany.primarydb.BeanName] entities share the same JPA entity name: [BeanName] which is not allowed!
    at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.addEntityBinding(InFlightMetadataCollectorImpl.java:305)
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:822)
    ... 148 common frames omitted

共有1个答案

梁丘经艺
2023-03-14

问题是您应该直接禁用默认的Spring Data JPA存储库初始化。

这可以通过指定spring.data.jpa.repositories.enabled=false配置属性(通过启动参数或application.properties)来实现

 类似资料:
  • 我正在JDeveloper 11.1.1.4中开发一个JAX-WS Web服务,它应该使用以前部署到WebLogic服务器的JAR中的EJB。WebService项目和EJB项目都是我自己的代码,但我想分别部署它们。现在我正在试验这种设置。 在Examplejb项目中,我有一个实现远程接口示例的bean ExampleBean。 在该项目中,我有两个部署描述符(ejb-jar.xml和weblog

  • 问题内容: 您将如何在不同的环境中处理跨数据库查询。例如,db1-development和db2-development,db1-production和db2-production。 如果要在从db2到db1的开发中进行跨数据库查询,则可以使用完全限定的名称,即[db1-development]。[schema]。[table]。但是,如何在不同环境之间维护查询和存储过程?[db1-develop

  • 问题内容: 例如,mysql引用表名使用 注意` 其他数据库是否曾经使用过不同的char来引用其表名 问题答案: 引号的这种使用称为定界标识符。这是SQL的重要组成部分,因为否则您将不能使用以下标识符(例如表名和列名): 包含空格:“我的桌子” 包括特殊字符和标点符号:“我的表格” 包括国际字符:“私のテーブル” 区分大小写:“ MyTable” 匹配SQL关键字:“表” 标准SQL语言对定界标识

  • 问题内容: 我想从具有存储为clob的XML列为testclob的表TRAPTABCLOB中使用sql提取Decision的值。 样本XML如下。 问题答案: 尝试 这是一个sqlfiddle演示

  • 问题内容: 我们有一个应用程序被部署了120次,每个应用程序的配置略有不同。我们希望将配置存储在数据库中,以进行审核和管理。 如何不使用XML直接从数据库实例化Spring Bean? 谢谢 问题答案: 您不能有零个XML配置(除非您使用JavaConfig,这不会使情况有所不同)。您可以将其中一些外部化到数据库,并使用custom 。有关如何实现此目的,请参见本文。

  • 现在我们需要用JOOQ创建left join查询,什么将left join来自两个不同数据库的两个表 示例本机SQL查询(贝娄),我们需要这个查询是建立使用JOOQ框架,而不是使用本机SQL。直到现在我还没有找到任何解决方案,也许JOOQ不支持这个功能