开发者

Mapping one Entity class to two different databases (Oracle and Ingres)

开发者 https://www.devze.com 2023-02-02 16:27 出处:网络
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 o

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 col开发者_高级运维lection element) to Oracle.

I would appreciate your suggestions and help.

Thanks, PK


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号