We have an application (spring framework + hibernate3) which manages entities, in the way that we allow inserts, updates, deletes and searches of these entities (like millions of applications out there, I know). Each entity has its own java bean, and the subsequent hibernate mapping (.hbm.xml) and implementation for the persistent tasks (obvious). A POJO entity model, right.
That we want to do, is to allow the creation of new entities at runtime, so then these ones could be accessed using the management functionality. Each new entity will have their own custom attributes:
1. An unknown number of basic attributes: VARCHAR (string), NUMBER (integer), ...
2. An unknown number of relations with other beans.
In a POJO model, this means that we would need a new java bean class, a mapping configuration file. So, theoretically:
1. We will have to create as many tables as the new entity need.
2. A new bean which describes the new entity (theoretically this task could be done with libraries and APIs like BCEL or ASM).
3. A new mapping file .hbm.xml
4. A dynamic way of manipulating this new data.
Problems with this utopian task:
1. Create a new class with ASM or whatever will be insane.
2. When a SessionFactory is created, it can't be reloaded by adding new class or mapping files. So, we'll need to create a new one, or just destroy the existing one and re-create it again? (just wondering ...).
I've been reading the documentation and I've found two interesting sections:
1. Dynamic Models
2. Xml Mappings.
I'm wondering if this 'features' may help me to achieve this quite difficult task. But I feel that a need a new mapping file for each new entity, mapping it to a java bean. Well, not extending this post so much, a few questions:
1. Would I need a new java class for this entity, or is there a way to map a generic bean to a table? Like a HashMap, Map, Set, Vector, whatever of attributes. Something like:
<Column_Name,Object>
2. Every new entity will need its own mapping file?
3. If each new entity will need its own mapping file, is secure to configure a new SessionFactory (adding the new one). What implications this solution would have?
4. Hibernate will manage itself the creation of new tables into the schema or We will have to create the tables first?
This extensive post comes here because we want hibernate to manage DB sessions and transactions. I think we could achieve this task using a simple jdbc solution.
Thanks for, at least, reading this post,
Miguel.
_________________ But Mermaids Have a more Terrible weapon that their singing, That is, their silence
|