I am working on a project for a client that indexes large files. One of the goals of the rewrite was to also do it in a way that any database could easily be used with it. So it was decided that hibernate would be used.
We got it all working with hibernate using hbm.xml mapping. But just recently two new requirement have been added. Firstly they want to be able to specify the type of an index (ie string, int etc) currently it only supports strings. Secondly they want it to make the structure more normalized, as currently a query string to do a search is very complex.
There have been two thoughts on how to do this. 1. A table for each of the data types. 2. Give the admin user the ability to create new tables on the fly (ie we currently have a table that takes 10 strings and 2 ints. The new file to be indexed takes 11 strings and 2 ints so make a new table).
The proposed process for this would be:
Startup looking like this:
1. Init Hibernate as we do now.
2. Check DB to see what tables have been created dynamically in the past.
3. Add the HBM.XML files for those tables to the configuration; maybe generated on the fly or stored in DB.
4. Re-create the session's factory with the updated configuration. All tables should be accessible.
Creating a new table:
1. Init Hiberanate configuration with no mappings.
2. Add the single mapping for the new table.
3. Run SchemaExport to create the table.
4. Re-init session's factory as above with the newest addition. The new table should be accessible.
I am thinking number 2 does not sound like a very good solution.
Could an experienced member please provide feedback.
|