facebook

Problem using Hibernate Mapping with MyEclipse Hibernate

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #267558 Reply

    sunil1808
    Member

    Hi,
    Could anyone help me solve this strange Hibernate Problem?

    I’m using Hibernate : 3.1 Core Library downloaded from MyEclipse.
    MySQL DB.

    I’m getting the following error:

    Caused by: org.hibernate.MappingException: Foreign key (FKB67294CC6C15E404:catalog_entry [id])) must have same number of columns as the referenced primary key (catalog_entry [CATALOG_ENTRY_ID,id])
    The 2 referred tables are:

    CATALOG:

    ‘catalog’, ‘CREATE TABLE `catalog` (
    `ID` int(10) unsigned NOT NULL auto_increment,
    `DESCRIPTION` varchar(45) NOT NULL default ”,
    `CATLG_ENTR_ID` int(10) unsigned default NULL,
    PRIMARY KEY (`ID`),
    KEY `Index_2` (`CATLG_ENTR_ID`),
    CONSTRAINT `CATLG_ENTR_ID` FOREIGN KEY (`ID`) REFERENCES `catalog_entry` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1’

    CATALOG_ENTRY:
    ‘catalog_entry’, ‘CREATE TABLE `catalog_entry` (
    `ID` int(10) unsigned NOT NULL auto_increment,
    `PROD_CATALG_ID` int(10) unsigned NOT NULL default ‘0’,
    `PRIC_CATALG_ID` int(10) unsigned NOT NULL default ‘0’,
    PRIMARY KEY (`ID`),
    KEY `Index_2` (`PROD_CATALG_ID`),
    KEY `Index_3` (`PRIC_CATALG_ID`),
    CONSTRAINT `PROD_CATALG_ID` FOREIGN KEY (`ID`) REFERENCES `product` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT `PRIC_CATALG_ID` FOREIGN KEY (`ID`) REFERENCES `price` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1′

    The Hibernate mapping are:
    catalog.hbm.xml:

    <hibernate-mapping
    >
    <class
    name=”com.app.pojo.Catalog”
    table=”catalog”
    >

    <id
    name=”id”
    column=”id”
    type=”int”
    >
    <generator class=”native”>
    </generator>
    </id>

    <set
    name=”catalogEntries”
    table=”catalog_entry”
    lazy=”false”
    cascade=”save-update”
    sort=”unsorted”
    >

    <key
    column=”CATALOG_ENTRY_ID”
    >
    </key>

    <many-to-many
    class=”com.app.pojo.CatalogEntry”
    column=”id”
    outer-join=”auto”
    />

    </set>

    <property
    name=”description”
    type=”string”
    update=”true”
    insert=”true”
    column=”description”
    not-null=”true”
    />
    </class>

    </hibernate-mapping>

    CatalogEntry.hbm.xml:
    <hibernate-mapping
    >
    <class
    name=”com.app.pojo.CatalogEntry”
    table=”catalog_entry”
    >

    <id
    name=”id”
    column=”id”
    type=”int”
    >
    <generator class=”native”>

    </generator>
    </id>

    <many-to-one
    name=”price”
    class=”com.app.pojo.Price”
    cascade=”save-update”
    outer-join=”auto”
    update=”true”
    insert=”true”
    column=”price”
    not-null=”true”
    />

    <many-to-one
    name=”product”
    class=”com.app.pojo.Product”
    cascade=”save-update”
    outer-join=”auto”
    update=”true”
    insert=”true”
    column=”product”
    not-null=”true”
    />
    </class>

    </hibernate-mapping>

    Thanking you,
    Sunil.

    #267610 Reply

    Riyad Kalla
    Member

    Did you use MYEclipse to reverse-engineer these tables? The DDL actually looks fine…

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Problem using Hibernate Mapping with MyEclipse Hibernate

You must be logged in to post in the forum log in