4 Replies Latest reply on May 26, 2007 1:53 PM by fhh

    Best Practice Question

    Martin Duclos Newbie

      I am working on a data collection web app using jboss seam/ejb3. The app in question will collect workforce/employment information about an individual. Now, for 1 individual there could be as many as 400 elements collected. What would be the best way to model an entity bean for that situation?

      Note that it would be fairly easy to logically group the elements by categories such as demographics, past employment, education, etc.

      All i know at this point is that an entity with ~400 getter/setter doesnt sound like the best way to approach the issue.

      Any help/suggestion will be greatly appreciated.

        • 1. Re: Best Practice Question
          Anton Anton Newbie

          >>Note that it would be fairly easy to logically group the elements by >>categories such as demographics, past employment, education, etc.
          I would suggest to wrap all attribute in appropriate classes and combine them into one main class (or operate with them from one class) which has with related classes LAZY fetch strategy

          • 2. Re: Best Practice Question
            Expert

            This problem is not jpa specific. What database schema works best is at least depending on

            a.) the relationship of the attributes,

            b.) how many of those attributes are actually needed during procesing,

            c.) the expected amount of data.

            So I would suggest you create an entity relationship model first.

            Regards

            Felix

            • 3. Re: Best Practice Question
              Martin Duclos Newbie

              Felix,

              Thanks for your reply. I am all new to this thing so excuse my "newbieness". Ok, so what if I have a table named participants and each row represent 1 participant with the 400 or so data elements collected for that participant. What would be the best way to handle that with EJB3? Most of the attributes are small, ie: gender, are you employed?, etc.


              • 4. Re: Best Practice Question
                Expert

                This is not so much an EJB question but a question of database design.

                There is no such thing as "the right way" to it. It all depends on the data and what you want to do with it. One of the key question is: Should you normalize the data?

                This depends on what you want to do with that data. For example if you only want to dump records as fast as possible into the database I would use the fully denormalized form you suggested. However, this scenario is very unlikely.

                So usually you will want to have some denomalization. How much depends again what you want to do. If you will want to filter your partictpants according to different criteria you might consider a star schema. For maximum transaction speed you would prefer to normalize the data further.

                Normalization makes especially sense if you want to enforce data consistency. In your example you could move the former employers to a table of their own to make sure that there are no different spelling of the company's name.

                So I cannot really help you. You know best what you want to do with the data in your application.

                Regards

                Felix