The current version of my application has fixed set of entities as it is developed for use by users of a specific (pharmaceutical) domain.
Now we wish to enhance it to be used by users from other domains (finance, instrumentation).We need to provide a metadata driven system, where entities will be decided by the administrator of application on the fly.
The example case is :
Presently we have fixed entities such as Brand, Region, TherapeuticArea, Topic. All of these entities are functionally categorized as Objectives. There are fixed classes, mapping files for each of them (and fixed tables with relationships among them).So the entity-relationship is static in nature as in any standard application.
In future we will know only one entity 'Objective'. Administrator should be able to create any Objective type entity such as Brand, Region etc, on the fly. He can also specify relationships among them(in most of the cases it is many-to-many relationship).Then these entities should be used as application level entities and user will be able to store their instances, update them as well as delete them.
There are two ways I can think, this can be achieved
1.Creating an entity "Objective" with fixed set of attributes with a "type" attribute, to describe type of entity(brand or region etc).In this case defining the relationships among the entities will be a challenge.
We will need a separate mapping table to map the many-to-many relationships between these entities. Consider following class
Class Objective {
Long Id
attribA;
attribB;
type;
Set <Objective>parents; //many-parents
Set <Objective>children; //many children
}
If I create a mapping table say “Objective_Mapping” it will have both keys from the same entity i.e. Objective. How can write an hbm.xml file for such a configuration?
2.The second option is to create the entity classes (Brand, Region) and respective hbm.xml files on the fly and use them in application at runtime. Is this possible using “Configuration” class API ?
|