开发者

Joining tables in NHibernate gets "collection element mapping has wrong number of columns"

I'm having trouble mapping a many-to-many relationship with a join table. The errror message I am getting is "collection element mapping has wrong number of columns"

My db schema is basically:

Joining tables in NHibernate gets "collection element mapping has wrong number of columns"

. Despite the picture from SQL Server Management Studio, the database is Sqlite.

My mapping file is:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

<class name="Design" table="Design">
  <id name="DesignID" column="DesignID" type="Int32">
    <generator class="native"/>
  </id>
  <property name="Name" type="String" column="Name" />
  <property name="DisplayOrder" type="Int32" column="DisplayOrder" />
  <property name="ChangeDate" column="ChangeDate" type="DateTime"/>
  <set name="DesignMeasures" table="DesignProperties" cascade="save-update,delete-orphan" >
    <key column="DesignID" />
    <many-to-many column="PropertyID" class="DesignProperties" unique="true" />
  </set>
</class>

  <class name="Properties" table="Properties">
    <id name="PropertyID" column="PropertyID" type="Int32">
      <generator class="native" />
    </id>
    <property name="Name" type="String" column="Name" />
    <property name="Value" type="String" column="Value" />
  </class>

  <class name="DesignProperties" table="DesignProperties">
    <composite-id>
      <key-many-to-one class="Design" name="Desi开发者_JAVA技巧gnID" column="DesignID" />
      <key-many-to-one class="Properties" name="PropertyID" column="PropertyID" />
    </composite-id>
  </class>

</hibernate-mapping> 

I know I'm doing something wrong, but I can't figure it out. What am I doing wrong? How do I fix it?


DesignProperties is either a many-to-many relationship or an entity, not both.

Since it doesn't have any properties of its own, I'd remove the DesignProperties class along with its mapping, and just leave a collection of Property (not Properties; your class name should be singular) in Design.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜