5 Replies Latest reply on Oct 5, 2005 11:29 AM by pabry

    Common superclass to all entities?

    phon

      i want all my entities to contains fields that hold when they are last modified and by wath user. i created a superclass called BaseEntity that implements these properties and als holds the id because all other entities in the project will inherit from this base class.

      i use TABLE_PER_CLASS as inheritence strategy. i'm having trouble with the id assignment for my entities.. when i use GeneratorType.AUTO (as i did before) i get this error message :

      Problem creating service jboss.j2ee:service=EJB3,module=support.par
      org.hibernate.MappingException: Cannot use identity column key generation with <union-subclass> mapping for:

      When i try GeneratorType.TABLE or GeneratorType.SEQUENCE, none of my entities get an id (they all have 0).

      I also tried to implement this superclass as and EmbeddableSuperClass but as i need to hold a reference to a user (which is also an entity) i can't use an EmbeddableSuperclass because it can only hold basic types as attributes.

      Anyone knows what the prolem could be? Or is there any other, better strategy to get these attributes into each entity in de system?

      Thx a lot in advance

        • 1. Re: Common superclass to all entities?
          phon

          i'm still struggling with the "EmbeddableSuperclass classes may only have basic attributes" message. Also can i create a hierarchy of EmbeddableSuperclasses ?

          What i want is something like this :

          BaseEntity (abstract with audit fields and id information)
          |
          ----> MultiLanguageEntity (asbtract with descriptions in multiple languages)
          |
          ------> ActualEntity

          i can't get it working with the id field on the BaseEntity. It works though when i specify ID fields on all the actualentities, but i can't really work with BaseEntities in polymorphic calls because they don't know getId()
          anyone has a solution for this or am i trying something completely stupid and is there another better way?

          • 2. Re: Common superclass to all entities?
            epbernard

            This is not supported yet.

            • 3. Re: Common superclass to all entities?

              I used this and it seems to work - I have three fields I want in every Entity class.

               23 @EmbeddableSuperclass(access=AccessType.PROPERTY)
               24 public abstract class PObject implements Serializable{
               25
               26 private int id;
               27 private User updateUser;
               28 private Timestamp updateTimestamp;
               29
               30 public Timestamp getUpdateTimestamp() {
               31 return updateTimestamp;
               32 }
               33 public void setUpdateTimestamp(Timestamp updateTimestamp) {
               34 this.updateTimestamp = updateTimestamp;
               35 }
               36
               37 @ManyToOne
               38 public User getUpdateUser() {
               39 return updateUser;
               40 }
               41 public void setUpdateUser(User updateUser) {
               42 this.updateUser = updateUser;
               43 }
               44
               45 @Id(generate = GeneratorType.AUTO)
               46 public int getId() {
               47 return id;
               48 }
               49 public void setId(int id) {
               50 this.id = id;
               51 }
               52
               53
               54 }
              


              Every entity class extends this class. Hope this helps.

              • 4. Re: Common superclass to all entities?
                phon

                indeed, i have a similar setup and it also works here

                i only seem to experience problems when gettin the objects back from the database, some fields in from the EmbeddableSuperclass are set (in my case the id is in the superclass, and it definately gets set) but others are not (the createdDate is in the database, but the property doesn't get set when i query the database.

                do you experience the same problem ?

                • 5. Re: Common superclass to all entities?
                  pabry

                  I have a similar problem. However, It worked for me in 4.0.3RC2, but now I'm having problems in 4.0.3.

                  You can se my problems in this thread: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=70401