I have two separate db schemas (or 2 users’ tables in Oracle’s jargon) – schemaA and schemaB.
schemaA, among other tables, has table:
domain(id NUMBER PK, description(VARCHAR2(10))
schemaB has table:
q_user(id NUMBER PK, username VARCHAR2(8) NOT NULL, domain_id NUMBER, CONSTRAINT foreign key references schemaA.domain(id))
Java class QUser has the following properties:
Long id,
String username,
Domain domain
The question: is it possible to configure Hibernate to initialise QUser object using two different data sources (schemaA and schemaB)? If so, how do I do it?
Also I’m using Spring 3, Hibernate 3.6 and Oracle 10g.
I came across Spring techniques to define multiple data sources and swap them dynamically, but I’m not sure that this can be used to initialise a single object.
Any help appreciated.
Thanks
In your domain mapping, you can enter the schema name also.
With XML:
With annotations:
Then, you don’t need multiple datasources. You set up a single datasource that connects using schemaB user (since in the schemaB table you have permission to access the schemaA table – hence the foreign key).