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