0

I have an application with two databases and upon deployment I want to generate the tables for the entities in different two databases. For example if I have Entity1, Entity2 and Entity3, I want Entity1 and Entity2 tables to be generated in database1 and Entity3 table to be generated in database2. As in:

Entity1 =====> DB1
Entity2 =====> DB1
Entity3 =====> DB2

Is there a specific annotation that deals with database-entity mapping?

This is my persistence unit:

  <persistence-unit name="DB1_PU" transaction-type="JTA">
      <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
      <jta-data-source>jdbc/DB1</jta-data-source>
      <properties>
         <property name="eclipselink.ddl-generation" value="create-tables"/>
      </properties>
  </persistence-unit>

  <persistence-unit name="DB2_PU" transaction-type="JTA">
      <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
      <jta-data-source>jdbc/DB2</jta-data-source>
      <properties>
         <property name="eclipselink.ddl-generation" value="create-tables"/>
     </properties>
  </persistence-unit>
fareed
  • 3,034
  • 6
  • 37
  • 65

1 Answers1

0

Ok that was an easy solution, I've just figured it out.

I used

@Table(name="ENTITY_1", schema="DB1.dbo")
@Table(name="ENTITY_2", schema="DB2.dbo")

and successfully mapped entities to the correct DB.

fareed
  • 3,034
  • 6
  • 37
  • 65