title: Hibernate/JPA: Mapping entities to different databases
body: <p>I have an application which manages 3 databases. I use hibernate with JPA on seam framework.</p>
  
  <p>So I have a persitence.xml file with three persitence-unit like this (I remove properties for db2 and db3):</p>
  
  <pre><code>&lt;persistence-unit name="db1" transaction-type="JTA" &gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;jta-data-source&gt;db1source&lt;/jta-data-source&gt;
      &lt;properties&gt;
          &lt;property name="hibernate.dialect"
              value="org.hibernate.dialect.Oracle10gDialect" /&gt;
          &lt;property name="hibernate.connection.driver_class"
              value="oracle.jdbc.driver.OracleDriver" /&gt;
          &lt;property name="hibernate.hbm2ddl.auto" value="validate" /&gt;
          &lt;property name="hibernate.show_sql" value="false" /&gt;
          &lt;property name="hibernate.format_sql" value="true" /&gt;
          &lt;property name="hibernate.default_schema" value="SI_TEC" /&gt;
          &lt;property name="hibernate.validator.apply_to_ddl" value="false" /&gt;
          &lt;property name="hibernate.transaction.manager_lookup_class"
              value="org.hibernate.transaction.WeblogicTransactionManagerLookup" /&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  
  &lt;persistence-unit name="db2" transaction-type="JTA"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;jta-data-source&gt;d2source&lt;/jta-data-source&gt;
  &lt;/persistence-unit&gt;
  
  &lt;persistence-unit name="db3" transaction-type="JTA"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;jta-data-source&gt;d3source&lt;/jta-data-source&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>In my seam components.xml file, I create 3 managed-persistence-context to map seam with my hibernate configuration.</p>
  
  <p>Finally, I have several entities and my problem is here. I need to persist some entities in db2 and other in db3. So database schema are different and when I deploy my application, I get this error:</p>
  
  <pre><code>org.hibernate.HibernateException: Missing table: PORTAILPERMISSION
      at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1113)
      at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:139)
      at org.hibernate.impl.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:349)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
      at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
      Truncated. see log file for complete stacktrace
  </code></pre>
  
  <p>Because, the table PORTAILPERMISSION doesn't exist in db2.</p>
  
  <p>My question is:</p>
  
  <p>How to specify in entity class what database (or persitence-unit) must be used to validate entity in startup ?</p>
  
  <p>Thanks for your help.</p>