6 Replies Latest reply on Dec 14, 2004 8:46 AM by bill.burke

    composite PK and joined-inheritance

    pmoermans

      Hello,

      Let's say we have a class B that extends a class A.
      A has a primary key: id.
      B has a composite primary key: id + serial

      I tried to implement this following the tutorial on composite key and joined inheritance but when I look in the database, B has only ID as the key.

      Can it be implemented ?
      If yes, how ?


      Many thanks,

      Pierre

        • 1. 3858086
          bill.burke

          I don't think this is possible. If you have inheritance, i believe the primary key class/field needs to be the same for all subclasses. I'll double check with the EG.

          Bill

          • 2. Re: composite PK and joined-inheritance
            pmoermans

            It works when using TABLE_PER_CLASS or SINGLE_TABLE strategies.

            In my case, this is ennoying because A should be abstract. Therefore I don't need to have a table in the database for that class.

            Is is possible to declare the inheritance in Hibernate and specify not to create a table for class A ?

            Many thanks,

            Pierre

            • 3. Re: composite PK and joined-inheritance
              bill.burke

              Don't mark the abstract class as an @Entity.

              • 4. Re: composite PK and joined-inheritance
                bill.burke

                ONE MORE THING....


                Keep these kind of use cases coming...I'm am forwarding your input to the EG as its good stuff.

                Bill

                • 5. Re: composite PK and joined-inheritance
                  pmoermans

                  Not marking the abstract class as @Entity only works if there is no relationship with other classes.

                  One of the reason I wanted to use an abstract class is that their should be a ManyToOne relationship with this class.
                  When I don't specify it as @Entity, I get a "normal" MappingError.

                  What I'd like to do is:

                  A is an abstract class, with no table in the DB
                  B and C inherits from A
                  D has many instances of A.

                  Pierre

                  • 6. 3765226
                    bill.burke

                    Checked with EG. I was correct. You are not allowed to do this as per the spec. In an inheritance mapping, all primary keys must be the same types and defined int he base class.