2 Replies Latest reply on Mar 14, 2008 1:46 PM by mokua

    Entity extends abstract class

    anb1

      Hello everyone,


      Maybe this is a Hibernate question but I'm trying my luck here anyway :)


      We are designing an entity that we want to subclass from an abstract class:


      PhoneContact and EmailContact which extends Abstract Contact.


      Now, I'm not sure how this must be done. Should the @Entity annotation be on the subclasses, on the mother or on both ? And why ?


      Thanks in advance

        • 1. Re: Entity extends abstract class
          shane.bryzak

          You only need the @Entity annotation on the sub classes (the abstract superclass itself is not an entity).

          • 2. Re: Entity extends abstract class
            mokua

            @MappedSuperclass
            public abstract class ModelBase {
                 @Id
                 @GeneratedValue(generator = "tigerSequenceGenerator")
                 @Column(name = "ID")
                 
                 protected Long id;
            
                 @Version
                 @Column(name = "OBJ_VERSION")
                 private Integer version;
                    
                    //more attributes
                    //getters and setters
            } 
            
            
            @Entity
            @Table(name = "blah")
            @AttributeOverrides( {
            //overrides base class
            })
            public class SomeEntity extends ModelBase implements Serializable {
                 //more attributes..
            }