title: Why is my EmbeddedId in hibernate not working?
body: <p>I have a compound Primary Key <code>(IDHOLIDAYPACKAGE, IDHOLIDAYPACKAGEVARIANT)</code> in table <code>HolidayPackageVariant</code> where <code>IDHOLIDAYPACKAGE</code> refers to entity <em>HolidayPackage</em> with a <strong>Many</strong> to <strong>One</strong> relationship between <em>HolidayPackageVariant</em> and <em>HolidayPackage</em>.</p>
  
  <p>When I try to do the compund PK mapping in HolidayPackageVariant, I get the following error:</p>
  
  <blockquote>
    <p>Initial SessionFactory creation
    failed.org.hibernate.annotations.common.AssertionFailure: Declaring
    class is not found in the inheritance state hierarchy:
    org.wah.model.holidaypackage.HolidayPackageVariantPrimaryKey</p>
  </blockquote>
  
  <p>Can someone please tell me what am I doing wrong here ?</p>
  
  <p>MY POJOs look like this:</p>
  
  <blockquote>
    <p>HolidayPackageVariant:</p>
  </blockquote>
  
  <pre><code>@Entity
  @Table(name="HOLIDAYPACKAGEVARIANT")
  public final class HolidayPackageVariant {
  
      private HolidayPackageVariantPrimaryKey idCompound;
  
      @EmbeddedId
      public HolidayPackageVariantPrimaryKey getIdCompound() {
          return idCompound;
      }
  
      // other code
  }
  </code></pre>
  
  <blockquote>
    <p>HolidayPackageVariantPrimaryKey    </p>
  </blockquote>
  
  <pre><code>@Embeddable
  public final class HolidayPackageVariantPrimaryKey implements Serializable {
  
      private Integer idHolidayPackageVariant;
      private HolidayPackage holidayPackage;
  
      public HolidayPackageVariantPrimaryKey(){}
  
      public HolidayPackageVariantPrimaryKey(int id, HolidayPackage pkg){
          setIdHolidayPackageVariant(id);
          setHolidayPackage(pkg);
      }
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "IDHOLIDAYPACKAGEVARIANT", nullable = false)
      public Integer getIdHolidayPackageVariant() {
          return idHolidayPackageVariant;
      }
  
      @Id
      @ManyToOne(fetch=FetchType.LAZY, cascade={CascadeType.ALL})
      @JoinColumn(name="IDHOLIDAYPACKAGE", nullable=false)
      public HolidayPackage getHolidayPackage() {
          return holidayPackage;
      }
  
      // equals and hashCode
  }
  </code></pre>
  
  <blockquote>
    <p>HolidayPackage</p>
  </blockquote>
  
  <pre><code>public final class HolidayPackage {
      private Set&lt;HolidayPackageVariant&gt; holidayPackageVariants = new HashSet&lt;HolidayPackageVariant&gt;(0);
  
      @OneToMany(fetch=FetchType.LAZY, cascade={CascadeType.ALL}, mappedBy = "idCompound.holidayPackage")
      public Set&lt;HolidayPackageVariant&gt; getHolidayPackageVariants() {
          return holidayPackageVariants;
      }
  
      // other code
  }
  </code></pre>