-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: confused about foreign key generation
PostPosted: Mon Nov 12, 2007 8:37 am 
Newbie

Joined: Thu Apr 12, 2007 2:34 am
Posts: 5
Can someone help clear my confusion over foreign key generation? My problem, essentially, is that, in my phpAdmin interface I get the following error:

PRIMARY and INDEX keys should not both be set for column `order_id`

OK - I understand the reason why this is being generated is because I have an index both on the primary key and the foriegn key - and that one of them is superflous, but I don't understand what is generating it.

Herewith my mappings:



Code:
<hibernate-mapping>
    <class name="com.florencestudios.model.order.Order" table="orders">
        <id name="id" type="int" column="order_id">
            <generator class="native"/>
        </id>
      <property name="date"  type="timestamp" column="order_date" not-null="true"/>
      <set name="orderItems" table="books_orders" lazy="false" ><!--lazy="true"-->
            <!--<key column="order_id" not-null="true" />-->
            <many-to-many column="book_id" class="com.florencestudios.model.Book"/>
        </set>
      <property name="orderTotal" not-null="true"/>
      <property name="shippingMethod" not-null="true"/>
      <many-to-one name="shippingAddress" class="com.florencestudios.model.order.Address" column="shippingaddress_id"  not-null="true" lazy="false" /><!--lazy="true"-->
      <many-to-one name="customer" class="com.florencestudios.model.order.Customer" column="customer_id" update="true"  not-null="true" lazy="false" /> 
      <property name="payment_method" not-null="true"/>
      <property name="isDispatched" not-null="true"/>
    </class>
</hibernate-mapping>


Code:
<hibernate-mapping>
    <class name="com.florencestudios.model.Book" table="books">
        <id name="id" type="int" column="book_id">
            <generator class="native"/>
        </id>
        <property name="headline"/>
        <property name="abe_id" not-null="true" /><!--not-null="true"-->
        <property name="author" type="java.lang.String" length="2000000" />
        <property name="short_title" type="java.lang.String" length="2000000" /><!-- type="text"-->
        <property name="long_title" type="java.lang.String" length="2000000" /><!-- type="text"-->
        <property name="publisher" type="java.lang.String" length="2000000" /><!-- type="text"-->
        <property name="year"/>
        <property name="price"/>
        <property name="description_1" type="java.lang.String" length="2000000" /><!-- type="text"-->
        <property name="description_2" type="java.lang.String" length="2000000" /><!-- type="text"-->
        <property name="note_1" type="java.lang.String" length="2000000" /><!-- type="text"-->
        <property name="note_2" type="java.lang.String" length="2000000" /><!-- type="text"-->
        <property name="note_3" type="java.lang.String" length="2000000" /><!-- type="text"-->
        <property name="bibliography" type="java.lang.String" length="2000000"/><!-- type="text"-->
        <property name="isavailable" not-null="true"/><!-- type="text"-->
        <property name="issold" not-null="true"/><!-- type="text"-->

        <set name="categories" table="books_categories" lazy="false">
            <!--<key column="book_id"/>-->
            <many-to-many column="category_id" class="com.florencestudios.model.Category"/>
        </set>
    </class>

</hibernate-mapping>


Can anyone see where I'm going wrong? Many thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 12, 2007 10:30 am 
Newbie

Joined: Thu Apr 12, 2007 2:34 am
Posts: 5
I posted the above entry to soon...
With the <key> child elements commented out for the <set> parent elements, it doesn't even parse. Seems like I have no choice but to include them.

To extrapolate my proplem a little further, with the databases schema which the above mappings produce (with <key> elements uncommented) is as follows:
Code:
DROP TABLE IF EXISTS `books_orders`;
CREATE TABLE `books_orders` (
  `order_id` int(11) NOT NULL,
  `book_id` int(11) NOT NULL,
  PRIMARY KEY  (`order_id`,`book_id`),
  KEY `FK7513CA1AD5195D11` (`book_id`),
  KEY `FK7513CA1A87695C83` (`order_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


As I understand it, I don't need both the PRIMARY KEY and FOREIGN KEY indexes. But how do I ensure that it doesn't create them?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.