2 Replies Latest reply on Jul 21, 2006 8:28 AM by Tor Egil Jacobsen


    Tor Egil Jacobsen Novice

      I recently put this in the EJB forum and later discovered that this is where it should be:
      I am trying to develop a entity which extends another entity and which use the annotation @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS), but this only provides an exception as the sub class does not have an @Id annotated:

      org.hibernate.MappingException: Cannot use identity column key generation with <union-subclass> mapping for: concept.entity.Entity

      However: If I do annotate this @Id, I get this one:

      org.hibernate.AnnotationException: Unable to define/override @Id(s) on a subclass: concept.entity.En


      I had the idea that @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) would give a new table with every field from the sub classes and mother class in this table. I searched the final draft on persistence for this notation but I came up with no suitable instances found.

      Is this assumption of the strategy correct or (especially since this is not working) is it another way of doing this?

        • 1. Re: Persisting
          Tor Egil Jacobsen Novice

          I discovered the annotation @MappedSuperClass which does exactly what I intend to achieve. However; there is a new situation with this.

          I now have a class (@MappedSuperClass) called MappedClass which an @Entity called Entity extends. I now want to extend Entity with another @Entity called TransactionEntity, but this results in the error message: The type Entity cannot be the superclass of TransactionEntity; a superclass must be a class

          This is not what the final draft on persistence states:

          Both abstract and concrete classes can be entities. Entities may extend non-entity classes as well as
          entity classes, and non-entity classes may extend entity classes.

          Is there a way to achieve a @MappedSuperClass with several subs which is entites?

          • 2. Re: Persisting
            Tor Egil Jacobsen Novice

            Bug searching and testing of the @MappedSuperClass ensures me that it works as I hoped.

            I am sorry for using thread space for such errors when my frustration growed after reading x documents.

            The compiler error (which was indeed strange) was my own fault (who else). In my source I used "extend Entity" which made the compiler think that I was trying to extend javax.persistence.Entity and not the Entity class in my package.