4 Replies Latest reply on Dec 30, 2005 9:42 PM by epbernard

    Extending model classes

    ashetty

      I have been dirtying my hands with EJB3 using annotations.

      In the past with Hibernate, I have used the bottom-up approach to jump start my coding:
      - Middlegen to get first-cut hbm
      - hbm2java to auto generate base model classes (therefore they can be overwritten)
      - subclasses extending base classes (these contain custom logic, as base classes can be overwritten again)
      - making subclasses the actual persistable entity in hbm file.

      And now with EJB3 I was looking to do something similar. I have to put in @Entity and @Id annotations (at least) in the subclass to declare my it as an entity . However getId() was "code-generated" as part of the base class.

      It does not make sense to generate everything in the base class and then put in the PK "@Id getId(){}" in the sub class.

      Any suggestions?

      Thanx !!

        • 1. Re: Extending model classes
          ashetty

          No reply ..sigh!

          There is some logic that is part of microflow within a process. I feel this ought to be implemented in stateless session beans. However, I would like to make a distinction between process logic versus logic that belongs in a domain model. Therefore, I would like my model classes to be functionally rich and containing all logic pertaining to domain model. This works great if you are handcoding all your model classes and then making them persistent by doing all that annotation business. However, if I have a process to auto-generate model classes from database tables, I would like subclasses to contain afore mentioned logic. In Hibernate, this was not an issue (I simply mention the subclass as the entity). If I use annotations, implementing this becomes more of a challenge.

          Clarification on code generating base model classes:- In parallel development happening with multiple teams, often times, the database schema may evolve as the project progresses. In this case, it makes sense to have a single owner to manage base classes, while teams make contributions to the sub-classes.

          • 2. Re: Extending model classes
            epbernard

            use @EmbeddedSuperclass

            • 3. Re: Extending model classes
              ashetty

              Thnx Emmanuel,

              However, if I use @EmbeddedSuperClass, the base class cannot be the target of a persistent relationship, right?

              • 4. Re: Extending model classes
                epbernard

                right