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: composite key and relationship to table with composite key
PostPosted: Thu Dec 21, 2006 1:45 pm 
Beginner
Beginner

Joined: Mon Oct 02, 2006 6:46 pm
Posts: 32
Hibernate version: NHibernate1.2.0Beta 2

Name and version of the database you are using: SQL Server 2000

The generated SQL (show_sql=true): n/a

I have the following mapping file:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="HELM.Domains.Orderlines,HELM.Domains" table="orderlines" lazy="false">
    <!--<id name="Orderid" column="OrderID" type="System.Int32" unsaved-value="any" >
      <generator class="assigned"/>
    </id>-->
    <composite-id access="field">
      <key-property name="WarehouseId" column="WarehouseID" type="System.Int32"/>
      <key-property name="ItemId" column="ItemId" type="System.Int32"/>
      <key-property name="OrderLineid" column="OrderLineID" type="System.Int32" />
    </composite-id>

    <!--<property column="OrderLineID" name="OrderLineid" type="System.Int32"/>-->
    <property column="ActualWeight" type="System.Decimal" name="ActualWeight" />
   
    <!-- Relationships-->
    <many-to-one name="Items" class="HELM.Domains.Inventory,HELM.Domains" cascade="none" update="false" insert="false">
      <column name="Warehouseid"/>
      <column name="ItemId"/>
    </many-to-one>
  </class>
</hibernate-mapping>


I am getting an error when I try to save the Orderline object. The error is:

NHibernate.ADOException: could not insert: [HELM.Domains.Orderlines#HELM.Domains.Orderlines][SQL: INSERT INTO orderlines (OrderID, ActualWeight, Warehouseid, ItemId, WarehouseID, ItemId, OrderLineID) VALUES (?, ?, ?, ?, ?, ?, ?)] ---> System.Data.SqlClient.SqlException: Column name 'WarehouseID' appears more than once in the result column list.
Column name 'ItemId' appears more than once in the result column list..

How do I specify both a composite key, and a relationship to a table with a composite key without nhibernate trying to persist fields that are common to both the key and the relationship each time they appear?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 2:49 pm 
Newbie

Joined: Wed Dec 20, 2006 9:00 am
Posts: 10
Location: Brazil (GMT-3)
This is just a guess since I've never used composite keys before, but do you know in which situation <key-many-to-one> should be used in place of <key-property>? Would it be related to your problem?

_________________
If a post helps you, rate it!


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.