I'm currently developing an application that has some interesting constraints and am evaluating if Hibernate is the right persistence mechanism to use. The application stores a large number of individual names and attributes about these names. Each individual, or "Entity", can have a number of vary attributes that describe the Entity. The number of attributes, theoretically, is not finite. For example, Entity A may have 6 attributes, such as Name, Address, or City. Entity B may have 7 attributes, such as Name, Address, DOB, SSN etc. Note Entity A does not track DOB or SSN (would be NULLs in a DB if stored in one big table). As more and more information is gathered about these Entities, the number of attributes is virtually limitless. Currently, there can be over 40-50 attributes per Entity and growing. Any individual Entity uses an arbitrary subset of these attributes. This is also compounded by the problem that an entity can have multiple values per attribute. For example, an Entity can have 5 values for Alias attribute.
Programmatically, we are looking to tackle this issue by having an HashMap that stores an Enum value for the attributes as key and the value of that attribute. For example
public class Entity {
private Map attributes = new HashMap();
public addAttribute(AttributeEnum key, String value) {
attributes.put(key,value);
}
}
enum Attributes {
LastName,
FirstName,
Address1,
Alias1,
Alias2,
}
public class UseCase {
public static void main(String[] args) {
Entity entity = new Entity();
entity.addAttribute(Attributes.LastName, "Johnson");
entity.addAttribute(Attributes.Alias1,"Joey");
}
}
Although we are still grappling with the idea of multiple values for a particular attribute (i.e. Alias1, Alias2... AliasN, seems ugly and is an issue), some questions arise
1. How would/Can Hibernate persist an Entity object?
2. What DML would Hibernate create for such a relationship?
3. Are there any other design suggestions to ease persistence given the constraints (near limitless attributes, possible multiple values per attribute)?
4. A relational DB may not be ideal, this may be a job for an XML or LDAP repository. If using an XML db, what changes need to be made in the program design to make Hibernate work?
5. Assuming a relational DB is mandated, what are the options that Hibernate provides?
Thanks very much
|