Currently I’m thinking that doing an application commits transaction on multi-databases with different schema, I’m confused of the pattern that doing such action. i will dependent on the following software’s and tools.
- Hibernate as JPA provider
- Oracle database
- WebSphere application server 6.1 server.
Well if I understand you correctly you want to use the same object (Entity) and persist it to 3 different schema (different then dynamically choosing one of the 3 at run-time). You will need to define a different persistent unit for each schema. Now most providers merge the annotation and XML metadata (mappings) so you may be able to just get away with defining your schema in the mapping xml files and using annotations for the rest (assuming the table and columns are the same accross schemas). If that does not work you will need to maintain all your mappings in the mapping XML files.
One of your mapping files might looks something like this
Another option you can consider that is hibernate specific is the below property (but I would prefer the approach listed above):
Anyway will have to have something like this:
Now if you need all of these to share a common transaction you will have to follow Jeanne's advice and use XA.