Jpa: how to use different databases with relationships between them

In one Mysql database installation, I can create different databases with database relationships. My goal, for example, is to use the relationship between people in database A and addresses in database B. It seems that recently EclipseLink has added support for such cases. Composite storage unit

Unfortunately, more comprehensive examples are hard to find, and above all, the composite persistence unit combines persistence.xml files from different jar. In the project I'm working on now, I do not have classes and entities divided into different banks based on the database to which they refer. Honestly, watching the documentation on Eclipselink, I can’t understand the real effort to make the code compatible with what is required for the Composite persistence component. Do you have any experience? Are there any alternative ways?

Thanks Filippo

+4
source share
1 answer

Are there databases of different databases or different schemas in the same database?

If these are just different schemes, then you do not need compound storage units, just set the scheme to @Table.

For different databases, you can use compound storage units, the documentation is here,

http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Composite_Persistence_Units

You do not need to have all the classes of persistence units in the banks (although this is the easiest way to do this. You can just have all the classes in the root bank and list the classes in the .xml and on persistence have a composite persistence.xml file in the composite banks.

+3
source

Source: https://habr.com/ru/post/1380368/


All Articles