File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to commit transaction on multi-databases with different schema ?

 
sherif hathout
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
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.

Any idea.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33671
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2 factor commit (XA drivers) allow you to write to different databases and commit in one transaction. You'd need different JPA entities for each database/table.
 
sherif hathout
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it means that if i have table exist in 3 databases, i need to create 3 entities although the tables have the same structure . how about redundancy? please declear with more details.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33671
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah. I read different schema and though different columns. If my only difference was the schema name, I'd use JDBC and a loop.

If I had to use JPA, I'd subclass the entity to have different classes. I can't think of a way to do it cleanly in JPA.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Hope that helps
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic