1 Reply Latest reply on Aug 13, 2010 9:53 AM by Sean Tozer

    abstract entity and subclasses for components

    Rob Shepherd Newbie

      Recently we had,




      @Entity
      @Name("user")
      @Scope(SESSION)
      public class User { ... }



      But now we must change it to the following structure:


      public abstract class User { ... }
      
      public class UserTypeA extends User { ... }
      
      public class UserTypeB extends User { ... }




      However,


      I've tried various combinations of the @Entity, @Name and @Scope annotations,


      It seems I can't have multiple sub-types with @Name


      Two components with the same name and precedence - component name: user



      But if they exist on User SEAM complains that User is abstract.


      Then, making User non-abstract (not ideal) I see it get's installed (But only the super-type)
      The other types don't get a mention.


      I see examples like this have been raised, but this is a simple case of polymorphism, where the concrete sub-types provide minor implementation differences.  The whole application (apart from a single other method) just requires:


      @In User user



      Any hints on what to do?


      Thanks and kind regards


      Rob




        • 1. Re: abstract entity and subclasses for components
          Sean Tozer Newbie

          Try the following mapping:


          @MappedSuperClass
          abstract class User { ... }
          



          @Entity
          @Table(..)
          class UserA extends User { ... }
          



          That will map UserA to the correc table, whatever it is in your setup, while still alowing both user types to be stored in a User variable. The trick of course is the MappedSuperClass, which makes Seam (through Hibernate) aware of the class and hierarchy without actually trying to map it to any instantiable entity.