• 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

Can we change database at runtime in JPA

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

Can we change the database details at runtime and the JPA entity manager will point to new database. This is for high availability. If master node is down I will get an event and I need to update the DB details. and after that all transactions should go to new DB

Thanks
 
Saloon Keeper
Posts: 26541
187
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rakhs Nair wrote:Hi All,

Can we change the database details at runtime and the JPA entity manager will point to new database. This is for high availability. If master node is down I will get an event and I need to update the DB details. and after that all transactions should go to new DB

Thanks



JPA can work with multiple databases at the same time, but each one has its own connection factory.

Coding HA into your app is likely to be cumbersome, however. A better option would be a lower-level HA option, such as an HA database driver. Some databases (such as MongoDB) are actually designed for such things, but as a general rule, the stock JDBC drivers aren't. I think, however, that a way to get that kind of behavior when you haven't got an HA driver may be to use a local proxy. Something like the PL/Proxy for PostgreSQL or Mysql::Proxy.

Local proxies have the ability not only to abstract your apps from specific database addresses, but also to add other useful abilities like host-wide database buffer caches, which can boost performance if many different apps (or cluster-copies of the same app) are running on the local host machine.

There are also various tricks that you can do when setting up a database to enhance its availablility.
 
Bartender
Posts: 1108
19
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most database vendors provide failover features, I suspect this would solve your problem.
 
Rakhs Nair
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for your quick reply..


But the problem is I need to support with existing design and database. I cannot change these. the system is already in place and we need to hook our component in to it which is using JPA.

So only way for me is to change the database details when I get the event.

Can we change the DB?



 
Tim Holloway
Saloon Keeper
Posts: 26541
187
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If things are really that important, then for the longer term I'd really recommend configuring the databases themselves for high availability.

However, as a quick fix, a DB proxy has the advantage of rapid deployment without the need to modify either apps or database servers. Basically, you just install the proxy, pointing to the servers, then reconfigure your apps to point to "localhost" and the proxy port number.
 
Rakhs Nair
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any solution for this scenario?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic