开发者

hibernate change database dynamically for maintenance

开发者 https://www.devze.com 2023-02-16 07:31 出处:网络
I have a java webapp using hibernate over MYSQL db.I need at least an hour of data maintenance daily, hence I need to bring down the db and switch to the backup db.开发者_StackOverflow中文版

I have a java webapp using hibernate over MYSQL db. I need at least an hour of data maintenance daily, hence I need to bring down the db and switch to the backup db.开发者_StackOverflow中文版

I don't see an elegant way to switch to another db from my app using hibernate. Is there?

Other totally different ways for database maintenance is welcome.


As you are using a Java WebApp, I assume you are using a container (like Tomcat) or an application server (like JBoss). In both cases, you should be using managed connections by the container, via JNDI. In such case, you can just use JMX (or the admin console) to change the actual datasource, to point to the backup DB, clean the pool and reopen new connections. When you are done, just perform the same steps, pointing the datasource to the actual database.

If you are not using managed connections by the container, you are out of luck. As the Hibernate configuration is static, you'll need to bring down your app, deploy a new version of it with your persistence.xml/hibernate.cfg.xml pointing to the backup, do the maintenance, and deploy the "old" version when you are done.

0

精彩评论

暂无评论...
验证码 换一张
取 消