-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Complex Persistence Challenge
PostPosted: Wed Oct 31, 2007 9:30 am 
Beginner
Beginner

Joined: Mon Nov 07, 2005 11:06 pm
Posts: 28
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 01, 2007 9:03 am 
Beginner
Beginner

Joined: Mon Nov 07, 2005 11:06 pm
Posts: 28
Well, I decided to use an approach that works nicely, but I still would love to hear suggestions for persisting the object model I described.

I chose to create methods to serialize each of the form node types to XML, as well as serialize the entire form to XML. Then, I exposed a public property called FormXmlData...

Code:
public string FormXmlData
{
    get { return this.ToXml(); }
    set { this.LoadFromXml(value); }
}


Then, I simply map the property FormXmlData as a simple string value to the DB.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.