Nhibernate的一个问题

出现了这个问题 ,找了很久弄好,后来别人提供了一个链接

http://codeverity.com/timweaver/nhibernate-invalid-index-for-this-sqlparametercollection/ 

 

 Here's my mapping file: [I swear I'm switching to attributes first chance I get, but I learned the Xml mapping and time doesn't permit the change at this point]

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    schema="TestDB.dbo"    
    namespace="Domain.Foo"
    >
  <class name="Domain.Foo.ProfileP, Domain" table="ProfileP" lazy="false" >
    <id name="ID" column="ID" type="Int32" unsaved-value="0">
      <generator class="native" />
    </id>
    <property name="ProfileId" column="profileId" type="Int32" />
    <property name="PaymentId" column="paymentId"   type="Int32"  insert="false" update="false" />
    <property name="Status" column="status"    type="string" length="10" />
    <many-to-one name="PaymentS" class="Domain.Foo.Sub, Domain" column="paymentId" cascade="save-update" not-null="true"  />
  </class>
</hibernate-mapping>

 

The problem is the line in red. The PaymentID is the ID value of the PaymentS class in the Domain.Foo.Sub namespace. So, NHibernate already knew the ID value and was using it in the update/save queries. In effect it was declared twice in the mapping file: once explicitly and once implicitly via the many-to-one relationship. The fix was to add insert="false" and update="false" to the paymentId property.

I ended up purchasing the NHibernate in Action book via the early access program. So far I am pleased with the purchase. The book has shed light on a lot of pieces of information that were unclear to me. Getting concise and complete information on NHibernate seems to be a lot harder than I would have thought.

posted @ 2011-04-18 09:10  Sum_yang  阅读(469)  评论(1编辑  收藏  举报