4 Replies Latest reply on Jan 6, 2006 8:15 AM by sunnyyfl

    POJO Inheritance and EJB3

      Background:

      We are re-vamping our MDA framework to handle EJB3.

      The architecture calls for an abstract superclass that defines all of the UML-specified items - specifically, it implements all of the getters and setters based on the attributes in the diagram. This superclass would therefore contain all of the annotations to define table names, column names, relationships (from associations in the diagrams) , etc. It also contains abstract methods for all the operations in the diagram.

      A subclass that extends the above mentioned base class implements the operations from the diagram and allows for any required customizations.

      The Question:

      It appears that we cannot just put all of the annotations in the superclass and extend it for the subclass. The EJB3 engine (JBoss 4.0.3RC1) doesn't see the subclass as an Entity object. I don't think this is a case for EJB inheritance, because there is actually only one "object" even though it is implemented in multiple classes.

      How do we do what I am describing in EJB3? I would have thought that the annotations would inherit into the subclass, and the abstract nature of the superclass would keep it from being "implemented" by the EJB3 engine. Unfortunately, when the classes get deployed through the EJB3 deployer, the subclass doesn't get deployed as an entity bean, and the abstract class get deployed as an entity bean (with errors that it cannot handle the CMRs - which are of subclass types.)

      I have spent a significant amount of time looking for information about how this is handled in EJB3 - in the spec, in these forums, and in search engines - to no avail.

      I am interested in any ideas about how to make something like this work.

      Thanks in advance.

      Note: My apologies for posting this first to the EJB 3.0 design forum. (I don't believe this user forum existed at the time.) The question is in fact about something that doesn't seem to be addressed in the spec. If I am wrong, please point me at the relevent section.

        • 1. Re: POJO Inheritance and EJB3
          epbernard

          I've answered on the old formu but please forward discussions to the new one.

          • 2. Re: POJO Inheritance and EJB3

            It appears that this is fixed by using @EmbeddedSuperclass.

            Thanks to everyone that helped. Now we just need @EmbeddedSuperclass to work without the hibernate descriptor. (Should be next release from the other messages on the forums about @EmbeddedSuperclass.)


            • 3. Re: POJO Inheritance and EJB3
              ashetty

              Hi Mexcell,

              What about persistent relationships? I had the same problem. However, my abstract classes also had bidirectional relationships. Spec says that @EmbeddedSuperClass (now @MappedSuperClass) cannot be target of persistent relationship(FK).

              Where do you model your association? I doubt it could be the customizable subclasses.

              • 4. Re: POJO Inheritance and EJB3

                 

                "mexcell" wrote:
                It appears that this is fixed by using @EmbeddedSuperclass.

                Thanks to everyone that helped. Now we just need @EmbeddedSuperclass to work without the hibernate descriptor. (Should be next release from the other messages on the forums about @EmbeddedSuperclass.