title: Unable to find column reference in the @MapsId mapping: item_brandId
body: <p>I am trying to use multiple mapping and composite primary key. When I run my code, the code will generate exception. Here is my code.
  brand, item and bestseller table</p>
  <pre><code>CREATE TABLE IF NOT EXISTS `mydb`.`brand` (
    `brandId` INT NOT NULL AUTO_INCREMENT,
    `brandName` VARCHAR(45) NOT NULL,
    PRIMARY KEY (`brandId`))
  ENGINE = InnoDB;
  
  CREATE TABLE IF NOT EXISTS `mydb`.`item` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `itemId` INT NOT NULL,
    `itemDesc` VARCHAR(45) NOT NULL,
    `itemPic` BLOB NOT NULL,
    `itemBarcode` INT NOT NULL,
    `itemShortDesc` VARCHAR(45) NULL,
    `price` INT NOT NULL,
    `salesPrice1` INT NULL,
    `salesPrice2` INT NULL,
    `salesPrice3` INT NULL,
    `item_brandId` INT NOT NULL,
    `SubCategory_subCatId` INT NOT NULL,
    PRIMARY KEY (`id`, `item_brandId`, `SubCategory_subCatId`),
    CONSTRAINT `fk_Item_Brand1`
      FOREIGN KEY (`item_brandId`)
      REFERENCES `mydb`.`brand` (`brandId`),
    CONSTRAINT `fk_item_SubCategory1`
      FOREIGN KEY (`SubCategory_subCatId`)
      REFERENCES `mydb`.`subCategory` (`subCatId`)
      ON DELETE NO ACTION`
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  CREATE TABLE IF NOT EXISTS `mydb`.`bestseller` (
    `sellerId` INT NOT NULL AUTO_INCREMENT,
    `sellerName` VARCHAR(45) NULL DEFAULT NULL,
    `item_id` INT NOT NULL,
    PRIMARY KEY (`sellerId`, `item_id`),
    CONSTRAINT `fk_bestseller_item1`
      FOREIGN KEY (`item_id`)
      REFERENCES `mydb`.`item` (`id`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  </code></pre>
  <p><code>Brand.java</code></p>
  <pre><code>import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name=&quot;brand&quot;)
  public class Brand {
  
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      @Column(name=&quot;brandId&quot;)
      private int brandId;
      
      @Column(name=&quot;brandName&quot;)
      private String brandName;
      
      public Brand() {
          
      }
      
      public Brand(String brandName)
      {
          this.brandName=brandName;
      }
      //getter and setter 
  }
  </code></pre>
  <p>Item.java</p>
  <pre><code>package com.entity;
  
  
  import java.util.Arrays;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.IdClass;
  import javax.persistence.JoinColumn;
  import javax.persistence.OneToOne;
  import javax.persistence.Table;
  
  @Entity
  @Table(name=&quot;item&quot;)
  @IdClass(ItemEmbeddable.class)
  public class Item {
      @Id
      @Column(name=&quot;id&quot;)
      private int id;
      
      @Column(name=&quot;itemId&quot;)
      private int itemId;
      
      @Column(name=&quot;itemDesc&quot;)
      private String itemDesc;
      
      @Column(name=&quot;itemPic&quot;)
      private byte[] itemPic;
      
      @Column(name=&quot;itemBarcode&quot;)
      private int itemBarcode;
      
      @Column(name=&quot;itemShortDesc&quot;)
      private String itemShortDesc;
      
      @Column(name=&quot;price&quot;)
      private int price;
      
      @Column(name=&quot;salesPrice1&quot;)
      private int salesPrice1;
      
      @Column(name=&quot;salesPrice2&quot;)
      private int salesPrice2;
      
      @Column(name=&quot;salesPrice3&quot;)
      private int salesPrice3;
      
      @Id
      @OneToOne
      @JoinColumn(name=&quot;item_brandId&quot;,referencedColumnName=&quot;brandId&quot;)
      private Brand brand;
      
      @Id
      @OneToOne
      @JoinColumn(name=&quot;SubCategory_subCatId&quot;,referencedColumnName=&quot;subCatId&quot;)
      private SubCategory subcategory;
      
      public Item()
      {
          
      }
  
      public Item(int itemId, String itemDesc, byte[] itemPic, int itemBarcode, String itemShortDesc, int price,
              int salesPrice1, int salesPrice2, int salesPrice3) {
          this.itemId = itemId;
          this.itemDesc = itemDesc;
          this.itemPic = itemPic;
          this.itemBarcode = itemBarcode;
          this.itemShortDesc = itemShortDesc;
          this.price = price;
          this.salesPrice1 = salesPrice1;
          this.salesPrice2 = salesPrice2;
          this.salesPrice3 = salesPrice3;
      }
  
      //getter and setter
  }
  </code></pre>
  <p>ItemEmbedable.java</p>
  <pre><code>package com.entity;
  
  import java.io.Serializable;
  
  public class ItemEmbeddable implements Serializable{
  
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
      private int id;
      private int brand;
      private int subcategory;
      
      public ItemEmbeddable()
      {
          
      }
      
      public ItemEmbeddable(int id, int subCategory, int brand) {
          super();
          this.id = id;
          this.subcategory = subCategory;
          this.brand = brand;
      }
      //getter,setter, hashcode and equal
  }
  </code></pre>
  <p>BestSeller.java</p>
  <pre><code>package com.entity;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.IdClass;
  import javax.persistence.JoinColumn;
  import javax.persistence.OneToOne;
  import javax.persistence.Table;
  
  
  @Entity
  @Table(name=&quot;bestseller&quot;)
  @IdClass(BestSellerEmbeddable.class)
  public class BestSeller {
  
      @Id
      @Column(name=&quot;sellerId&quot;)
      private int sellerId;
      
      @Column(name=&quot;sellerName&quot;)
      private String sellerName;
      
      @Id
      @OneToOne
      @JoinColumn(name=&quot;item_id&quot;,referencedColumnName=&quot;id&quot;)
      private Item item;
  
      public BestSeller() {
          super();
          // TODO Auto-generated constructor stub
      }
      
  
      public BestSeller(String sellerName) {
          super();
          this.sellerName = sellerName;
          
      }
  
  }
  </code></pre>
  <p>BestSellerEmbeddable.java</p>
  <pre><code>package com.entity;
  
  import java.io.Serializable;
  
  public class BestSellerEmbeddable implements Serializable{
  
      private static final long serialVersionUID = 1L;
      private int sellerId;
      private int item;
      
      public BestSellerEmbeddable() {
          super();
          // TODO Auto-generated constructor stub
      }
  
      public BestSellerEmbeddable(int sellerId, int item) {
          super();
          this.sellerId = sellerId;
          this.item = item;
      }
  
      //getter and setter
  }
  </code></pre>
  <p>The code will generate following exception.How can I change my code to get it to work?</p>
  <pre><code>org.hibernate.AnnotationException: Unable to find column reference in the @MapsId mapping: item_brandId
  </code></pre>