Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate Error on session.Save

Tags:

nhibernate

I have an MVC app using NHibernate.

I created a model and tried to insert data into the db for the first time with NHibernate, so please go easy.

I get this error on the session.Save(object);

IndexOutOfRangeException was unhandled by user code

Invalid index 8 for this SqlParameterCollection with Count=8.

When I look at the data in the object using watch window all seems ok and also collections are inittialized.

Using SQL 2005.

Any ideas why this may be occurring please?

Malcolm

like image 394
Malcolm Avatar asked Apr 13 '09 07:04

Malcolm


1 Answers

I have had the same problem using NHibernate myself, the problem in my case was in the mapping. On my associations I have mapped a property containing the associated entity, and also a property with the association ID only.

The solution in my case was to add update="false" insert="false" to my mapping of the property containing the ID. Like this:

<property name="AssociationId" column="AssociationColumnName" update="false" insert="false" />
<many-to-one name="Association" column="AssociationColumnName" property-ref="Id" not-null="false" />
like image 93
fredrik Avatar answered Sep 18 '22 03:09

fredrik