openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MiƂosz Tylenda <mtyle...@o2.pl>
Subject Re: Can I map between multiple datasources?
Date Thu, 31 Dec 2009 09:34:48 GMT

> I've been assembling an app using OpenJPA 1.2.1 for a few weeks now.
> I've just come to the conclusion that the app is going to require
> reading data from more than one database datasource.  One user schema
> has most of the tables, but another user has some other tables.  There
> are some references between those groups of tables.
> 
> There's no way to specify multiple datasources in a single persistence
> unit, but I suppose I could implement multiple persistence units.  Is it
> possible to have an entity from one persistence unit reference an entity
> from another persistence unit?

I don't think there is a possibility to have an entity from one persistence unit reference
an entity from another persistence unit.

It is my understanding that your tables reside in multiple schemas and you are able to perform
joins between tables from different schemas at the SQL level. If this is the case, you can
take advantage of orm.xml and annotations - they allow you to specify a schema for each table,
for example:

@Table(name="CUST", schema="RECORDS")

Another idea is to check whether your database allows creation of synonyms/aliases. For example,
with Oracle you should be able to execute DDL like:

create synonym CUST for OAK.CUST;

Then, you can reference table CUST residing in schema OAK just as CUST and don't need to specify
schemas in your entity mapping. Possibly, you might need to modify user privileges in the
database.

Regards,
Milosz


Mime
View raw message