I was working on a project that involved merging 2 web applications into one. There was an old web application that was being brought into the same GUI as a new system. The old web application, let's call it oldWebApp, had its own POJOs being saved in an old database on an old server. The new web application had new POJOs being saved in a different database on a different MySQL server.
But I needed everything packaged up in the same WAR file. How to do it?
In applicationContext.xml, I had two "singleton" sessionFactories. Like:
Notice how there are TWO hibernate.cfg.xml files?
Next, you just write your Manager classes (analagous to in this tutorial) according to the appropriate database. Connect the appropriate Manager class with the appropriate database, still in applicatonContext.xml, like this:
So from here just mark up your POJOs using plain old Hibernate annotations and the application is like "who cares what database this object is in" and it just works. So sweet.
After all that, it turns out we decided to migrate the old POJOs onto the new database server after all, so I gutted this part of the configuration files after all. But it was still fun to get it working.
No comments:
Post a Comment