Hi, we have a situation where we allow users to specify custom additional fields for some of our objects. These need to be persisted in the database, but we can't simply put a serialized map in a blob column, as we also want to index the fields. I see from the documentation that we could use the dynamic-component tag in our hbm.xml, but that has two problems:
1. We would really rather use annotations in our models, rather than specifying the mappings in xml
2. Persisting deployment-specific modifications to the list of custom fields would mean modifying the xml file, which can cause problems if some of our models ever change and we need to merge the two when deploying a new version.
Ideally what I would like to do is create a Configuration object, add our annotated classes, modify the mapping for our customisable objects to specify the columns of the dynamic component, and ask Hibernate to update the database schema via alter table commands if needed. It would also be nice to allow for adding and dropping columns while an active session is open, but we can work around that by tearing down the entire session and recreating it with the new configuration - this is expected to be a rare operation.
What would be the best way to do this?
|