• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

How to save data in 2 db simultaneously by using Spring Hibernate

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

how can I save data in 2 different database like Oracle and Mysql simultaneously. I am using Spring 2.5 and Hibernate for my project.

Please help on this.

Thanks in advance
Ram
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ramanuj Dev wrote:Hi all,

how can I save data in 2 different database like Oracle and Mysql simultaneously. I am using Spring 2.5 and Hibernate for my project.

Please help on this.

Thanks in advance
Ram



You will have to have two different dataSources. One for each database, and with Hibernate you will need two SessionFactory(s) one for each database, or 2 EntityManagerFactory(s) if you are using Hibernate just as your implementation of JPA. And unless you use JTA, then you will also need two TransactionManagers.

This will be true whether you are using Spring or not. It is about the database stuff.

Mark
 
Ramanuj Dev
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,

Thanks for the response.
Now I am able to save data in 2 database(Oracle and MySQL) simultaneously.
I have another concerned here.
If I have only one database connection active and another database is stopped/disconnected, then I am getting error.
What i will set in my config file to fix this issue.
How I will select the active database through my config file???

Please help me on this.

Thanks in advance

Ram

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ram,
which behaviour are you expecting in case of nonactive database?
If you want to rollback the whole transaction, do something like this:

If you want to save data anyway in your active database, try this:


But remember that you will have to configure distrubuted transaction support in first case.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But remember that you will have to configure distrubuted transaction support in first case.



Be careful. While this is important, it adds confusion to the original poster.

So I am confused, if you want to save to one but not the other if it is down. Are you trying to do this as a failover or backup design? If not, then I would probably think that you wouldn't want a partial commit, you would want it to fail if one of them is down.

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic