0

I am newbie to ORM and JPA. I have a table called Table1 in Ingres. I need to copy Table1 from Ingres to Oracle. I have been successful in connecting to both databases. Is it possible to create only one Entity class called Table1 and then do this operation as follows: Get List from Ingres which has all the records from Table1. Persist List (wholly, if not then individually by collection element) to Oracle.

I would appreciate your suggestions and help.

Thanks, PK

Pujan
  • 1

1 Answers1

2

For this purpose, configure two persistence units pointing to different databases in persistence.xml file.

<persistence>
   <persistence-unit name="oracleDB">
      <jta-data-source>java:/OracleDB</jta-data-source>
       ...
   </persistence-unit>

   <persistence-unit name="ingresDB">
      <jta-data-source>java:/ingresDB</jta-data-source>
       ...
   </persistence-unit>
</persistence>

Persistence context is injected using annotation by the container for the given persistence-unit.

   @PersistenceContext(unitName="oracleDB")
   private EntityManager oracleEntityManager;

   @PersistenceContext(unitName="ingresDB")
   private EntityManager ingresEntityManager;

Then you can perform operation on databases by using respective entityManager instance.

Table name/structure must be same in both the databases & avoid using native functionality provided by vendors for portability.

Nayan Wadekar
  • 11,444
  • 4
  • 50
  • 73