6 Replies Latest reply on May 5, 2005 2:17 PM by epbernard

    Inheritance: Single Table Strategy

    mduffy_lists

      I understand the "Inheritance: Single Table Strategy" strategy presented in the EJB-3.0_Preview_5 tutorial. The DiscriminatorColumn, "ANIMAL_TYPE", is used to determine if the table row represents a CAT or a DOG.

      What if I do not want to discriminate between subclasses, but I just want to use inheritance to discriminate between a parent and a single subclass? For example, if I have a table with ten columns that represents Users, and I want to use only four of these columns in a class called, UserDisplayItem, how would I do this in the EJB-3.0_Preview_5?

      In EJB-3.0_Preview_4, I could simply make the entity annotations in each class and uses "extends". This does not work in EJB-3.0_Preview_5.

      Any suggestions?

      Thanks.

      Mike

        • 1. Re: Inheritance: Single Table Strategy
          epbernard

          Hum, you're shooting yourself in the foot, but anyway.
          Can you show me a simplified case that was working in preview 4 and that does not work anymore?

          • 2. Re: Inheritance: Single Table Strategy
            mduffy_lists

            Please explain the comment, "shooting yourself in the foot".

            Is there a better way to do this?

            Mike

            • 3. Re: Inheritance: Single Table Strategy
              epbernard

              Please show me your simplified case

              • 4. Re: Inheritance: Single Table Strategy
                mduffy_lists

                The code is on my home system, but the simple explanation is:

                tbl_user contains the columns: firstName, lastName, email, phone, addressId, etc.

                there is also a mapping table between tbl_user and tbl_roleType.

                The full entity bean, User, contains everything (the composite address object, the collection of role types and all fields).

                I want User to inherit from UserDisplayItem which just contains the fields: firstName and lastName. The reason is, I need to display brief user information in a table view and I do not need all the information contained in the full user object.

                Shouldn't I be able to mark up both classes with the entity annotations and then just have User extend UserDisplayItem?

                Mike

                • 5. Re: Inheritance: Single Table Strategy
                  mduffy_lists

                  Here is the exception I am getting that I wasn't getting before:

                  02:45:43,398 ERROR [JDBCExceptionReporter] Column not found message from server: "Unknown column
                  'user0_.TYPE' in 'where clause'"

                  • 6. Re: Inheritance: Single Table Strategy
                    epbernard

                    You can't do that using inheritance.
                    In Hibernate Annotations you can mark your extra properties as lazy @Basic(LAZY), but I'm not sure it will work in JBoss EJB3, you'll have to check.

                    Or preferably you can use a special query

                    "select new UserDisplayItem(u.firstname, u.lastname) from User u"
                    or use regular projection.