Hello,
I've got a situation that somebody must've solved before, but unfortunately can't find anywhere in these forums.
I have a persistant class with a large number of fields, between 20 and 25, that gets "derived" from one data source (think of this as a production DB), then persisted in another data source (a reporting DB). (I realize having the data in two places isn't ideal, but we need to insulate the production DB from internal reporting requests.)
Before switching over to Hibernate, I handled this with a home-baked AsymetricPersistantObject, which took two sets of DB fieldNames, one from Database A for use by a Factory.deriveAll() method, the other from Database B for use in a various CRUD operations (.load(), .find(), .store(), etc.). My thought for doing this with Hibernate was to define two mappings for my persistant class, one to the Production DB table, and a second to the Reporting DB table; then have a single DAO that held references to two DAOs (I'm using Spring), and handle the "derivation" something like so:
List allObjects = productionDAO.loadAll(PersisentClass.Class);
productionDAO.clear(); //detach allObjects, shouldn't be necessary
reportingDAO.storeOrUpdateAll(allObjects);
Problem is, Hibernate won't let me map a single POJO class twice. I tried getting around this by subclassing PersistantClass and mapping the subclass to the Production DB, then upcasting and saving as the new instances to the Reporting DB, but that shenanigan didn't work either.
Does anybody have a Hibernate solution for this? I know I could create two wholly independent classes, map them separately, and add a .createReportingClone() method to the "derived" version of the class, which just creates a new instance of the Reporting version and transfers over its contents; then loadAll(), loop-create the Reporting objects, and saveAll(); but that's awfully yucky.
Thanks in advance,
Rogers
|