2 Replies Latest reply on Sep 13, 2002 11:55 PM by dsundstrom

    Inherrit a CMP bean

    erikture

      Hello!

      Is it possible to have inherritance in CMP 2.0.
      I hava a BaseBean and a number of other beans that shall extend the BaseBean and add some fields to it.

      I have implemented it and tried to generate the code using XDoclet. When it all compiles JBoss says something about the ejbCreate methods having to have the same return type. If I specify them so they have the same return types, then the compiler complains about the findByPrimaryKey methods. They interfere with each other.

      Is this an unsolvable problem or can it be done?

      /Erik

        • 1. Re: Inherrit a CMP bean
          sursha

          You can do inheritance. You have to use same Key class.
          I mean you cant have base class's ejbCreate() return one primary key class and child class's ejbCreate() return another key class. You know in Java you cant override a method whose signature is different only in return type.
          Extend your remote interface and bean implementation classes. Implement ejbCreate() in only one bean class.
          Problem with inheritance approach is that you end up doing multi-table mapping if you have more cmp fields in child class.

          • 2. Re: Inherrit a CMP bean
            dsundstrom

            I suggest you use delegation (encapsulation) instead of inheritance as your relationships won't inherit.