1 Reply Latest reply on Oct 3, 2005 12:13 PM by epbernard

    @Embeddable Primary Key with @ManyToOne Relation

    bendis

      Hi!

      I have an entity bean with composite primary key, something like:

      @Entity
      class EntityBean {
       @Embeddable
       static class PK {
       String id1;
       String id2;
       }
      
       @EmebeddedId
       PK pk;
      
       @Column(nullable = false)
       int value;
      }


      and there are no problems, everything works and when I check the database, the primary key is composed of both 'id1' and 'id2'... But now I change 'id2' to be a foreign key of some other entity, let's say 'OtherEntity':

      @Entity
      class EntityBean {
       @Embeddable
       static class PK {
       String id1;
       @ManyToOne
       OtherEntity oe;
       }
      
       @EmebeddedId
       PK pk;
      
       @Column(nullable = false)
       int value;
      }
      
      @Entity
      class OtherEntity {
       @Id
       String id;
      }


      And when I check the database, the primary key of EntityBean is now composed only from 'id1'! Shouldn't 'otherentity_id' (the foreign key column in EntityBean table) be also part of the primary key?

      Is this a bug or correct behavior?

      Thanks,
      Bendis