I am looking for some on ideas for how to approach the following persistence challenge. I appreciate any suggestions!
I have a set of classes that define a "Form" and all of the items that a form might contain. For example, a form has things like pages, sections, text fields, checkbox fields, drop down list fields, titles, etc. My object model for the form works very nicely as long as I do not try to persist a defined form. I have never needed to until now.
Because many of the form items share similar properties, AND, I need to be able to work with form "nodes" in a polymorphic way, I used inheritance for many of the classes in the model. I have tried to illustrate the basic class list below showing the inheritance through indentation.
Code:
Form
FormNode
Page
Section
Group
Title
Spacer
FieldNode
TextField
CheckboxField
HiddenField
ListField
DropDownListField
RadioButtonListField
A few other classes are used, mostly as components...
Label
Note
Also, ListField objects may have a collection of ListItem objects.
OK, so each of the classes has some basic properties that can be mapped easily. But, the relationships between the items look like this and make it a little more complicated.
- A Form may have 0 or more Pages.
- A Page may have 0 or more FormNodes but not any nested Pages.
- A Section may have 0 or more FormNodes, but not any nested Sections or Pages.
- A Group may have 0 or more FormNodes, but not any nested Groups, Sections, or Pages.
- ListFields have a collection of ListItems.
My goal is to persist a form and its related items using Hibernate and using the simplest approach possible. I want to be able to save and retrieve a fully populated form object.
The main problem I am having is how to do this with as few tables as possible. For example, I would like to use a single table for all FormNode objects rather than creating tables for all of the subclasses. But, I do not know how to handle the hierarchical relationship between the items in the form, and also to handle the order of the items, which is important.
I appreciate any suggestions or help!
Kevin