Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I connect to multiple databases with one persistence unit?

I am using JPA with Hibernate as my JPA provider. My application need to connect to database defined in persistence.xml (default persistence unit) grab multiple configured systems from table and create for each of them EntityManagerFactory (systems differ only in connection params, dialect and driver).

Is it possible to do it with "template" persistence unit? For now I'm using different copy persistence unit for each system but it's seems senseless.

like image 677
laidlook Avatar asked Nov 14 '22 00:11

laidlook


1 Answers

You probably need to write your own JCA compliant connector that wraps the distinct DB connectors and expose that via JPA:

like image 178
alphazero Avatar answered Mar 16 '23 01:03

alphazero