Domanda

There are two tables DocumentType and EmployeeDocumentType. There are multiple rows in EmployeeDocumentType w.r.t DocumentType.

I need to use many to one mapping in EmployeeDocumentType. I am using following syntax:

<many-to-one name="DocumentType" column="DocumentTypeId" class="DocumentType" />

Data is coming correctly in EmployeeDocumentType object, but when I save details into EmployeeDocumentType, it is giving error as,

Invalid index 14 for this SqlParameterCollection with Count=14.

what might be the issue.

È stato utile?

Soluzione

This issue would be (almost for sure) related to the doubled mapping.

Check your mapping file for another place where the column="DocumentTypeId" could be used
(or by some default convention as name="DocumentTypeId")

<!-- example of doubled mapping could be Int property representing the Int column -->
<property    name="DocumentTypeId" column="DocumentTypeId" /> 
<many-to-one name="DocumentType"   column="DocumentTypeId" class="DocumentType" />

The solution is easy here, one of these must be marked as readonly

<property    name="DocumentTypeId" column="DocumentTypeId"
                                                       insert="false" update="false"/> 
<many-to-one name="DocumentType"   column="DocumentTypeId" class="DocumentType" />
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top