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.