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.
精彩评论