0 Replies Latest reply on Nov 25, 2013 1:12 AM by Ramesh Chokkapu

    Composite key + primary key as auto increment  in hbm.xml showing wrong

    Ramesh Chokkapu Newbie

      I am creating table like below.

       

       

      CREATE TABLE `Channel_Amenities` (

      `id` INT(10) NOT NULL AUTO_INCREMENT, `distributorId` INT(10) NOT NULL,

      `amenityID` INT(10) NOT NULL,

      `amenityName` VARCHAR(50) NOT NULL,

      `categoryID` INT(10) NOT NULL,

      `categoryName` VARBINARY(200) NOT NULL,

      PRIMARY KEY (`id`),

      UNIQUE INDEX `distributorId_amenityID_categoryID` (`distributorId`, `amenityID`, `categoryID`) )

      COLLATE='utf8_general_ci' ENGINE=MyISAM AUTO_INCREMENT=8;

       

      I am using Hbm like below :

       

      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE hibernate-mapping PUBLIC

          "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

          "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

      <hibernate-mapping>

      <class

        name="ChannelAmenities"

        table="hofesoda.Channel_Amenities">

        <meta attribute="class-description" inherit="false">

        @hibernate.class

        table="hofesoda.Channel_Amenities"

          </meta>

        <id name="id" type="java.lang.Integer" column="id">

        <meta attribute="field-description">

        @hibernate.id

        generator-class="assigned"

        type="java.lang.Integer"

        column="id"

              </meta>

        <generator class="native" />

        </id>

        <composite-id>

        <meta attribute="field-description" inherit="false">

        @hibernate.id

        generator-class="assigned"

              </meta>

        <key-property name="distributorId" column="distributorId"

        type="java.lang.Integer" length="11">

        <meta attribute="distributorId">

        @hibernate.property

        column="distributorId"

                  </meta>

        </key-property>

        <key-property name="amenityID" column="amenityID"

        type="java.lang.Integer" length="11">

        <meta attribute="field-description">

        @hibernate.property

        column="amenityID"

                  </meta>

        </key-property>

        <key-property name="categoryID" column="categoryID"

        type="java.lang.Integer">

        <meta attribute="field-description">

        @hibernate.property

        column="categoryID"

                  </meta>

        </key-property>

        </composite-id>

        <property name="amenityName" type="java.lang.String"

        column="amenityName">

        <meta attribute="field-description">

        @hibernate.property

        column="amenityName"

              </meta>

        </property>

        <property name="categoryName" type="java.lang.String"

        column="categoryName">

        <meta attribute="field-description">

        @hibernate.property

        column="categoryName"

              </meta>

        </property>

        </class>

      </hibernate-mapping>

       

      While using this above hbm showing as wrong.

      I need table id as primary key which is autoincrement.

      And (`distributorId`, `amenityID`, `categoryID`)  which are composite.

       

      Please suggest me, How to Generate HBM for above Table.