aspose file tools*
The moose likes Object Relational Mapping and the fly likes How to commit transaction on multi-databases with different schema ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to commit transaction on multi-databases with different schema ?" Watch "How to commit transaction on multi-databases with different schema ?" New topic
Author

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

sherif hathout
Greenhorn

Joined: Nov 02, 2004
Posts: 18
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29247
    
139

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
sherif hathout
Greenhorn

Joined: Nov 02, 2004
Posts: 18
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29247
    
139

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

Joined: Mar 07, 2010
Posts: 1632
    
    7

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


[How To Ask Questions][Read before you PM me]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to commit transaction on multi-databases with different schema ?
 
Similar Threads
one Entity for two Database Schemas
Attn: Kyle - Two Phase Commit in WebSphere 4.0
A design and performance question
How to commit transaction on multi-databases with different schema ?
Hibernate in a multi-server architecture