Filippo
Filippo

Reputation: 1159

jpa: how to use different databases with relationships between them

In a single Mysql database installation I can create different databases with cross-database relationships. My goal is, for example, to use relationships between people on database A and adresses on database B. It seems that EclipseLink has recently added support for such cases Composite persistence unit

Unfortunately more exhaustive examples are hard to find and above all the Composite persistence unit merges persistence.xml files from different jar. In the project I'm currently working on I don't have classes and entities divided in different jars based on the database they refer to. Frankly, watching the documentation on Eclipselink, I cannot figure out the real effort to make the code compliant with what Composite persistence unit requires. Do you have any experience with it ? Are there alternative ways ?

Thanks Filippo

Upvotes: 4

Views: 3162

Answers (1)

James
James

Reputation: 18379

Are you databases different databases or just different schemas on the same database?

If the are just different schemas, then you don't need composite persistence units, just set the schema in the @Table.

For different databases you can use composite persistence units, the documentation is here,

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

You don't need to have all of the persistence unit classes in the jars (although that is the easiest way to do it. You could just have all of the classes in the root jar, and list the classes in the persistence.xml, and on have the composite persistence.xml in the composite jars.

Upvotes: 3

Related Questions