title: Spring-data-jpa same table name on two datasources "Duplicate entity name"
body: <p>I'm using spring-data-jpa with two datasources, 
  but my two schema elettroforesi and capillare both have a table ANALISI</p>
  
  <p>and Eclipse show me the following error:</p>
  
  <pre><code>"Duplicate entity name "Analisi" found in the persistence unit. Entity names must be unique."
  </code></pre>
  
  <p>the Config are the following:</p>
  
  <pre><code>@Configuration
  @PropertySource({ "classpath:persistence-multiple-db.properties" })
  @EnableTransactionManagement
  @EnableJpaRepositories(
          basePackages = "com.interlabsrl.elfolab.persistence.multiple.repository.elettroforesi", 
          entityManagerFactoryRef = "elettroforesiEntityManager", 
          transactionManagerRef = "elettroforesiTransactionManager")
  @ComponentScan(basePackages={"com.interlabsrl.elfolab.controller",
          "com.interlabsrl.elfolab.persistence.multiple.service", 
          "com.interlabsrl.elfolab.persistence.multiple.cache"})
  public class ElettroforesiConfig {
  
      @Autowired
      private Environment env;
  
      public ElettroforesiConfig() {
          super();
      }
  
      @Bean
      @Primary
      public LocalContainerEntityManagerFactoryBean elettroforesiEntityManager() {
          final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
          em.setPersistenceUnitName("elettroforesi");
          em.setDataSource(elettroforesiDataSource());
          em.setPackagesToScan(new String[] { "com.interlabsrl.elfolab.persistence.multiple.model.elettroforesi" });
          final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
          em.setJpaVendorAdapter(vendorAdapter);
          final HashMap&lt;String, Object&gt; properties = new HashMap&lt;String, Object&gt;();
          properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
          properties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
          properties.put("hibernate.show_sql", env.getProperty("hibernate.show_sql"));
          properties.put("hibernate.format_sql", env.getProperty("hibernate.format_sql"));
          properties.put("hibernate.jdbc.batch_size", env.getProperty("hibernate.jdbc.batch_size"));
          em.setJpaPropertyMap(properties);
          return em;
      }
  
      @Bean
      @Primary
      public DataSource elettroforesiDataSource() {
          final DriverManagerDataSource dataSource = new DriverManagerDataSource();
          dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName")));
          dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("elettroforesi.jdbc.url")));
          dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("elettroforesi.jdbc.user")));
          dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("elettroforesi.jdbc.pass")));
          return dataSource;
      }
  
      @Bean
      @Primary
      public PlatformTransactionManager elettroforesiTransactionManager() {
          final JpaTransactionManager transactionManager = new JpaTransactionManager();
          transactionManager.setEntityManagerFactory(elettroforesiEntityManager().getObject());
          return transactionManager;
      }
  
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>@Configuration
  @PropertySource({ "classpath:persistence-multiple-db.properties" })
  @EnableTransactionManagement
  @EnableJpaRepositories(
          basePackages = "com.interlabsrl.elfolab.persistence.multiple.repository.capillare", 
          entityManagerFactoryRef = "capillareEntityManager", 
          transactionManagerRef = "capillareTransactionManager")
  @ComponentScan(basePackages={"com.interlabsrl.elfolab.controller",
  //      , "com.interlabsrl.elfolab.persistence.multiple.service" 
  //      "com.interlabsrl.elfolab.persistence.multiple.cache"
          })
  public class CapillareConfig {
  
      @Autowired
      private Environment env;
  
      public CapillareConfig() {
          super();
      }
  
      @Bean
      public LocalContainerEntityManagerFactoryBean capillareEntityManager() {
          final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
          em.setPersistenceUnitName("capillare");
          em.setDataSource(capillareDataSource());
          em.setPackagesToScan(new String[] { "com.interlabsrl.elfolab.persistence.multiple.model.capillare" });
          final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
          em.setJpaVendorAdapter(vendorAdapter);
          final HashMap&lt;String, Object&gt; properties = new HashMap&lt;String, Object&gt;();
          properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
          properties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
          properties.put("hibernate.show_sql", env.getProperty("hibernate.show_sql"));
          properties.put("hibernate.format_sql", env.getProperty("hibernate.format_sql"));
          properties.put("hibernate.jdbc.batch_size", env.getProperty("hibernate.jdbc.batch_size"));
          em.setJpaPropertyMap(properties);
          return em;
      }
  
      @Bean
      public DataSource capillareDataSource() {
          final DriverManagerDataSource dataSource = new DriverManagerDataSource();
          dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName")));
          dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("capillare.jdbc.url")));
          dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("capillare.jdbc.user")));
          dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("capillare.jdbc.pass")));
          return dataSource;
      }
  
      @Bean
      public PlatformTransactionManager capillareTransactionManager() {
          final JpaTransactionManager transactionManager = new JpaTransactionManager();
          transactionManager.setEntityManagerFactory(capillareEntityManager().getObject());
          return transactionManager;
      }
  
  }
  </code></pre>
  
  <p>while the entities: </p>
  
  <pre><code>package com.interlabsrl.elfolab.persistence.multiple.model.elettroforesi;
  
  @Entity
  @NamedQueries({
      @NamedQuery(name = "Analisi.findAll", query = "SELECT a FROM Analisi a")})
  @Table(schema="elettroforesi")
  public class Analisi implements Serializable {
  
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(name = "ID_ANALISI", nullable = false)
      private Integer idAnalisi;
      @Basic(optional = false)
      @NotNull
      @Column(nullable = false)
      private short tracciato;
      @Size(max = 30)
      @Column(length = 30)
      private String campione;
      @Size(max = 40)
      @Column(length = 40)
      private String reparto;
      @Column(name = "TOTALE_PROTEINE", precision = 12)
      private Float totaleProteine;
      @Column(name = "RAPP_AG", precision = 12)
      private Float rappAg;
      @Column(name = "DATA_MODIFICA")
      @Temporal(TemporalType.TIMESTAMP)
      private Date dataModifica;
      @Column(name = "DATA_VALIDAZIONE")
      @Temporal(TemporalType.TIMESTAMP)
      private Date dataValidazione;
      @Column(name = "DATA_CANCELLAZIONE")
      @Temporal(TemporalType.TIMESTAMP)
      private Date dataCancellazione;
      @OneToMany(mappedBy = "idAnalisiLink")
      private Collection&lt;Analisi&gt; analisiCollection;
      @JoinColumn(name = "ID_ANALISI_LINK", referencedColumnName = "ID_ANALISI")
      @ManyToOne
      private Analisi idAnalisiLink;
      @JoinColumn(name = "ID_ANALISI_IFE", referencedColumnName = "ID_ANALISI_IFE")
      @ManyToOne
      private AnalisiIfe idAnalisiIfe;
      @JoinColumn(name = "ID_ANALISI_NOTA", referencedColumnName = "ID_ANALISI_NOTA")
      @ManyToOne
      private AnalisiNota idAnalisiNota;
      @JoinColumn(name = "ID_PATOLOGICO", referencedColumnName = "ID_PATOLOGICO")
      @ManyToOne
      private Patologico idPatologico;
      @JoinColumn(name = "ID_PAZIENTE", referencedColumnName = "ID_PAZIENTE", nullable = false)
      @ManyToOne(optional = false)
      private Paziente idPaziente;
      @JoinColumn(name = "ID_SESSIONE", referencedColumnName = "ID_SESSIONE", nullable = false)
      @ManyToOne(optional = false)
      private Sessione idSessione;
      @JoinColumn(name = "ID_TIPO_VALIDAZIONE", referencedColumnName = "ID_TIPO_VALIDAZIONE", nullable = false)
      @ManyToOne(optional = false)
      private TipoValidazione idTipoValidazione;
      @JoinColumn(name = "ID_UTENTE_CANCELLAZIONE", referencedColumnName = "ID_UTENTE")
      @ManyToOne(fetch=FetchType.LAZY)
      private Utente idUtenteCancellazione;
      @JoinColumn(name = "ID_UTENTE_MODIFICA", referencedColumnName = "ID_UTENTE")
      @ManyToOne(fetch=FetchType.LAZY)
      private Utente idUtenteModifica;
      @JoinColumn(name = "ID_UTENTE_VALIDAZIONE", referencedColumnName = "ID_UTENTE")
      @ManyToOne(fetch=FetchType.LAZY)
      private Utente idUtenteValidazione;
      @OneToMany(mappedBy = "idAnalisi", fetch=FetchType.LAZY)
      private Collection&lt;AnalisiFrazione&gt; analisiFrazioneCollection;
      @OneToMany(mappedBy = "idAnalisi", fetch=FetchType.LAZY)
      private Collection&lt;AnalisiAntisiero&gt; analisiAntisieroCollection;
      @OneToMany(mappedBy = "idAnalisi", fetch=FetchType.LAZY)
      private Collection&lt;AnalisiSmc&gt; analisiSmcCollection;
      @OneToMany(mappedBy = "idAnalisi", fetch=FetchType.LAZY)
      private Collection&lt;AnalisiCampoFree&gt; analisiCampoFreeCollection;
      @OneToMany(mappedBy = "idAnalisi", fetch=FetchType.LAZY)
      private Collection&lt;AnalisiDati&gt;     analisiDatiCollection;
      @OneToMany(mappedBy = "idAnalisi")
      private Collection&lt;AnalisiNefelometrico&gt; analisiNefelometricoCollection;    
  
  ...
  
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>package com.interlabsrl.elfolab.persistence.multiple.model.capillare;
  
  ...
  
  @Entity
  @NamedQueries({
      @NamedQuery(name = "Analisi.findAll", query = "SELECT a FROM Analisi a")})
  @Table(schema="capillare")
  public class Analisi implements Serializable {
  
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(nullable = false)
      private Long id;
      @Column(name = "id_macchina")
      private Integer idMacchina;
      @Column(name = "id_metodiche")
      private Integer idMetodiche;
      @Column(name = "numero_sessione")
      private Integer numeroSessione;
      @Temporal(TemporalType.TIMESTAMP)
      private Date dataora;
      @Temporal(TemporalType.DATE)
      private Date data;
      @Size(max = 20)
      @Column(name = "barcode_provetta", length = 20)
      private String barcodeProvetta;
      @Size(max = 20)
      @Column(name = "barcode_rack", length = 20)
      private String barcodeRack;
      @Size(max = 100)
      @Column(name = "dati_lettura", length = 100)
      private String datiLettura;
      private Short acquisito;
  
      ...
  
  }
  </code></pre>